I defined the cbrt function to return a cube root. I need to get an integer back (even if it is close to the cube root, it will be acceptable in my case). However, when I put the scale as 0 to get an integer, I get numbers which are grossly incorrect. What is going on and how do I get an integer cube root out?    bc -ldefine cbrt(x) { return e(l(x)/3) }scale=1;cbrt(1000000)99.4scale=0;cbrt(1000000)54
BC not handling scale = 0 correctly
bc
Setting scale before calling cbrt() has the effect of setting the scale whilst cbrt() is evaluated. The way around it is to stash the scale as part of the function:define cbrt(x) { auto z, var; z=scale; scale=5; var = e(l(x)/3); scale=z; return (var); }which when called gives:scale=0; cbrt(1000000)99.99998Which seems to ignore that scale=0. This is because it evaluates cbrt() which temporarily sets the scale to 5 and calculates your cube root (to 5 floating points), assigns that to z and returns that value (which implicitly has scale set to 5). You can then apply the local scale=0 by simply dividing by 1:scale=0; cbrt(100000)/199