Re: Cube root on standard calculator Message #16 Posted by Dale Reed on 30 Oct 2012, 8:53 p.m., in response to message #15 by Namir
I tried this on a machine that uses single-precision IEEE floating point (32-bit), which has a range of about 1E+/-38 (and a bit smaller for non-normalized numbers). It works for input values from about 7.0E-25 to 4.0E22 (if I remember correctly -- did the test at work and I'm home now). Any smaller and the value diverges toward zero, and any bigger and the first iteration gives "infinity" (+1.$), and, so, the second gives "Not a Number".
I use the square root as the starting guess. Doing this, I can find some "goofy" extreme values that take maybe 14 or 15 loops to converge, but most "reasonable" numbers take 4 or 5. And the number it converges to is more accurate (in the cases I tested) than doing input ** (1.0 / 3.0) on the same machine. (I checked by taking result * result * result; some were easily checked by inspection: cuberoot(1000.0) converges to exactly 10.0 vs 9.9999...)
Unfortunately, I didn't have time to compare execution time.
Thanks for everybody's input on this thread. I learned a lot, and I'm saving this one in my "toolkit".
Dale
|