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=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC 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: Hans Marqvardsen Subject: Re: Calculating SQRT in ADA Date: 1999/03/24 Message-ID: <36F8D9B7.1F8D@ddre.dk>#1/1 X-Deja-AN: 458889348 Content-Transfer-Encoding: 7bit References: <7dbv6t$4u5$1@nnrp1.dejanews.com> <19990324201959.00800.00000708@ngol04.aol.com> Content-Type: text/plain; charset=us-ascii Organization: DDRE Mime-Version: 1.0 Reply-To: hm@ddre.dk_nospam Newsgroups: comp.lang.ada Date: 1999-03-24T00:00:00+00:00 List-Id: John Herro wrote: > > Robert Dewar wrote: > >> while ... > >> abs(Guess*Guess/X - 1.0) > 3.0*Dummy'Epsilon loop > > Why the epsilon test, this iteration will terminate to > > exact equality in any reasonable floating-point model ... > > I don't know if the Open Ada 83 compiler has a "reasonable" floating-point > model, but I do know that if I test for exact equality, instantiate with type > Float, and compute Sqrt(2.0) with that compiler, the program goes into an > infinite loop. I think that in general, you can't guarantee that Guess*Guess > will ever exactly equal X. > Clearly, in any floating-point model the square root of X can only be represented exactly for very few values of X. However any "reasonable" model may be expected to contain two neighbour numbers G and H such that G*G <= X <= H*H Then one may expect convergence to either G, or H, or to the alternating sequence G,H,G,H,... Hence you need the epsilon test after all, but probably the constant 3.0 can safely be reduced. Sincerely, Hans Marqvardsen (In my previous posting, please disregard the idea of excluding abs)