comp.lang.ada
 help / color / mirror / Atom feed
From: johnherro@aol.com (John Herro)
Subject: Re: Calculating SQRT in Ada
Date: 1999/03/26
Date: 1999-03-26T00:00:00+00:00	[thread overview]
Message-ID: <19990325232830.01123.00000079@ngol02.aol.com> (raw)
In-Reply-To: 7dei54$dv2$1@nnrp1.dejanews.com

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




  reply	other threads:[~1999-03-26  0:00 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-03-24  0:00 Calculating SQRT in ADA cmcrae
1999-03-23  0:00 ` Chris Morgan
1999-03-24  0:00   ` Marin David Condic
     [not found]   ` <36F913E0.75F51763@lmco.com>
1999-03-24  0:00     ` Ada 83 - Sometimes still chosen Richard D Riehle
1999-03-25  0:00       ` robert_dewar
1999-03-25  0:00         ` Richard D Riehle
1999-03-25  0:00           ` Larry Kilgallen
1999-03-26  0:00           ` robert_dewar
1999-03-26  0:00             ` Tom Moran
1999-03-26  0:00             ` Richard D Riehle
1999-03-26  0:00               ` Tom Moran
1999-03-26  0:00                 ` Larry Kilgallen
1999-03-29  0:00                 ` Marin David Condic
1999-03-29  0:00                   ` Tarjei Tj�stheim Jensen
1999-03-27  0:00               ` Matthew Heaney
1999-03-26  0:00             ` Tarjei Tj�stheim Jensen
1999-03-27  0:00               ` robert_dewar
1999-03-27  0:00                 ` Tarjei Tj�stheim Jensen
1999-03-25  0:00       ` robert_dewar
1999-03-25  0:00         ` Richard D Riehle
1999-03-25  0:00           ` Marin David Condic
1999-03-26  0:00           ` robert_dewar
1999-03-24  0:00     ` Calculating SQRT in ADA John Herro
1999-03-24  0:00       ` Hans Marqvardsen
     [not found]         ` <36FAA3DF.42C31CF@lmco.com>
1999-03-26  0:00           ` Tom Moran
1999-03-25  0:00       ` robert_dewar
1999-03-25  0:00         ` John Herro
1999-03-24  0:00           ` Hans Marqvardsen
1999-03-25  0:00             ` David C. Hoos, Sr.
1999-03-25  0:00           ` robert_dewar
1999-03-25  0:00             ` David C. Hoos, Sr.
1999-03-26  0:00               ` Howard W. LUDWIG
1999-03-26  0:00             ` Ole-Hjalmar Kristensen
1999-03-27  0:00               ` robert_dewar
1999-03-29  0:00                 ` Robert I. Eachus
1999-03-30  0:00                   ` robert_dewar
1999-04-02  0:00                     ` Robert I. Eachus
1999-04-03  0:00                       ` robert_dewar
1999-03-30  0:00                   ` robert_dewar
1999-04-02  0:00                     ` Robert I. Eachus
1999-03-25  0:00           ` robert_dewar
1999-03-26  0:00             ` John Herro [this message]
1999-03-26  0:00               ` Calculating SQRT in Ada David C. Hoos, Sr.
1999-03-26  0:00                 ` John Herro
1999-03-25  0:00       ` Calculating SQRT in ADA robert_dewar
1999-03-25  0:00     ` robert_dewar
1999-03-24  0:00       ` Howard W. LUDWIG
1999-03-25  0:00         ` Larry Kilgallen
1999-03-24  0:00 ` bob
1999-03-24  0:00   ` Niklas Holsti
1999-03-26  0:00     ` als0045
1999-03-26  0:00       ` als0045
1999-03-26  0:00     ` bob
1999-03-26  0:00 ` Marin David Condic
1999-03-26  0:00   ` David C. Hoos, Sr.
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox