From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,fedc2d05e82c9174 X-Google-Attributes: gid103376,public From: "Robert I. Eachus" Subject: Re: Calculating SQRT in ADA Date: 1999/03/29 Message-ID: <36FFF83A.BE789C93@mitre.org>#1/1 X-Deja-AN: 460503456 Content-Transfer-Encoding: 7bit References: <7dbv6t$4u5$1@nnrp1.dejanews.com> <19990324201959.00800.00000708@ngol04.aol.com> <7dei9a$dvo$1@nnrp1.dejanews.com> <7dhjhi$27a$1@nnrp1.dejanews.com> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii Organization: The MITRE Corporation Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 1999-03-29T00:00:00+00:00 List-Id: robert_dewar@my-dejanews.com wrote: > I have *far* more faith in library routines than in math > routines cooked up by programmers who do not know how to > compute elementary functions! > > I must say that in a *lot* of experience, I have never seen > a library sqrt function that was bad. As I said, this is a > particularly easy one (that does not mean it cannot be > messed up by people whose knowledge of numerical algorithms > is minimal :-) Robert, your memory is going as you are getting older. ;-) In the sixties and seventies, there were some extremely atrocious implementations in language run-time libraries. The worst horror was the URAND for the IBM 360 which caused dozens of peer-reviewed papers to be withdrawn. But I also remember many trigonometric libraries which used polynomical approximations that were good to only six decimal places--even for double precision. Notice that even one N-R iteration would have fixed that problem. (The justification! was that the same library function was used for both single and double precision, but most single precision users wanted speed. Of course, in many cases I was able to write faster library functions that were much more accurate for the double case, and gave LSB results for the single precision case. Of course, as Robert Dewar knows, the IEEE floating-point arithmetic project did a lot to fix the situation, and to get trig, log, and exponential functions officially in the hardware. Nowadays it is very hard to improve on the "hardware" IEEE instructions, even when they involve some software emulation. Back to the original topic, the best way to compute square roots is not to use NR, but to use the same algorithm you learned in school (with calculating the exponent correctly for floating-point values). On most RISC hardware it is slightly faster than one floating-point divide, so Newton-Rhapson can't compete. (Of course, the hardware instruction, if it is really done in hardware, is faster still.)