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/25 Message-ID: <19990324201959.00800.00000708@ngol04.aol.com>#1/1 X-Deja-AN: 458745647 References: <7dbv6t$4u5$1@nnrp1.dejanews.com> X-Admin: news@aol.com Organization: AOL http://www.aol.com Newsgroups: comp.lang.ada Date: 1999-03-25T00:00:00+00:00 List-Id: 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. Robert also wrote: >> Guess : Dummy := X; > Notice also that no one would actually program a square > root this way (with such a poor initial guess). You need > to do a table lookup to get the initial guess reasonably > close, otherwise you waste several iterations getting near > the target value. I agree that this poor initial guess causes the program to require several extra iterations, and that a table lookup for the initial guess would shorten the run time. However, my philosophy is, wherever possible, to minimize program complexity rather than execution time, to save programming and debugging effort. Computers are supposed to save people time. Convergence is very rapid. If we want to compute Sqrt(9.0) and the initial guess is 9.0, successive guesses, to nine significant digits, are 5.00000000, 3.40000000, 3.02352941, 3.00009155, 3.00000000. I admit that in cases where execution time must be minimized, the extra programming effort is called for, but in general my first rule is to minimize program complexity instead. - John Herro You can download a shareware AdaTutor program at http://members.aol.com/AdaTutor