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,FREEMAIL_FROM, 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: johnherro@aol.com (John Herro) Subject: Re: Calculating SQRT in Ada Date: 1999/03/26 Message-ID: <19990325232830.01123.00000079@ngol02.aol.com>#1/1 X-Deja-AN: 459218279 References: <7dei54$dv2$1@nnrp1.dejanews.com> X-Admin: news@aol.com Organization: AOL http://www.aol.com Newsgroups: comp.lang.ada Date: 1999-03-26T00:00:00+00:00 List-Id: Robert Dewar said: > The proper way for testing for convergence is to see if > the new guess is the same as the last guess! Hans Marqvardsen said: >> while X /= 0.0 and then >> abs(Guess*Guess/X - 1.0) > 3.0*Dummy'Epsilon loop > Where does the multiplier 3.0 come from? There are some cases where the loop will alternate between two guesses, so testing that the new guess is the same as the last guess won't guarantee convergence with every implementation. However, it might be possible to terminate when the guess is the same as EITHER the last guess OR the second-to-last guess. I can't prove to myself that the loop would always terminate in this case, but it seems likely that it will. I've found that with a multiplier of 1.0, the loop doesn't always terminate. With a multiplier of 10.0, not all displayed digits of the answer are correct when I simply use Put in an instantiation of Float_IO, without specifying Aft, Exp, etc. So I chose a multiplier that's approximately the geometric mean of 1.0 and 10.0. With the multiplier of 3.0, the loop seems always to terminate, and all displayed digits are correct. However, Robert Dewar is right when he says > The example here ... is not fully last bit accurate > ... and any library routine will undoubtedly do the > right things ... It's interesting to note that I have yet to see an Ada 83 compiler (except Ada/Ed), that DIDN'T come with a math package that included a square root routine. - John Herro http://members.aol.com/AdaTutor