comp.lang.ada
 help / color / mirror / Atom feed
From: johnherro@aol.com (John Herro)
Subject: Re: Calculating SQRT in ADA
Date: 1999/03/25
Date: 1999-03-25T00:00:00+00:00	[thread overview]
Message-ID: <19990324201959.00800.00000708@ngol04.aol.com> (raw)
In-Reply-To: 7dbv6t$4u5$1@nnrp1.dejanews.com

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




  reply	other threads:[~1999-03-25  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
     [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           ` Marin David Condic
1999-03-26  0:00           ` robert_dewar
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             ` Tarjei Tj�stheim Jensen
1999-03-27  0:00               ` robert_dewar
1999-03-27  0:00                 ` Tarjei Tj�stheim Jensen
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             ` Tom Moran
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 [this message]
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-03-30  0:00                   ` robert_dewar
1999-04-02  0:00                     ` Robert I. Eachus
1999-04-03  0:00                       ` robert_dewar
1999-03-25  0:00           ` robert_dewar
1999-03-26  0:00             ` Calculating SQRT in Ada John Herro
1999-03-26  0:00               ` 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   ` Marin David Condic
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