d85 has an error that makes it overly conservative in the number of iterations. Assuming that a. 64 bit IEEE floats gives 16 decimal digits of precision b. Each iteration doubles the number of digits Then the number of required iterations is (2^.x)-4, not 2^.x-16 . Thus:
d85a=: 4 : '-:@(+y&%)^:(0>.>._4+2^.x) x:!.0 %:y' 0j_10 ": y - *: 50 d85a y=: 2 _1.2898341200e_63 0j_10 ": y - *: 100 d85a y _2.0795900715e_127 0j_10 ": y - *: 500 d85a y _3.6529268908e_510 0j_10 ": y - *: 1000 d85a y _1.6679843587e_1020 0j_10 ": y - *: 50 d85a y=: 200003 _6.0239608276e_61 0j_10 ": y - *: 100 d85a y _4.5359449674e_127 0j_10 ": y - *: 500 d85a y _8.2676408642e_524 0j_10 ": y - *: 1000 d85a y _8.5441075207e_1053 ----- Original Message ----- From: "John Randall" <[EMAIL PROTECTED]> To: "Programming forum" <[email protected]> Sent: Friday, March 10, 2006 2:47 PM Subject: RE: [Jprogramming] More precision nightmares ... If you want to calculate a square root to a precision you specify, you need an algorithm, rather than expecting default behavior to work miracles. There is a J phrase that will do this using Newton's method: >From section 8A (still in J504 here) d85=: 4 : '-:@(+y.&%)^:(>.2^.1>.x.-16)x:%:y.' uses Newton's method to find x decimal digits of the square root of y. ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
