Tuesday, 20 August 2013

BC not handling scale = 0 correctly

BC not handling scale = 0 correctly

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 -l
define cbrt(x) { return e(l(x)/3) }
scale=1;cbrt(1000000)
99.4
scale=0;cbrt(1000000)
54

No comments:

Post a Comment