From: johnherro@aol.com (John Herro)
Subject: Re: Calculating SQRT in ADA
Date: 1999/03/24
Date: 1999-03-24T00:00:00+00:00 [thread overview]
Message-ID: <19990324125518.01416.00000432@ngol08.aol.com> (raw)
In-Reply-To: 36F913E0.75F51763@lmco.com
Here's a generic square root routine in Ada 83, taken from my AdaTutor program:
generic
type Dummy is digits <>;
function Sqrt(X :in Dummy) return Dummy;
function Sqrt(X :in Dummy) return Dummy is
Guess : Dummy := X;
begin
if X < 0.0 then
raise Constraint_Error;
end if;
while X /= 0.0 and then
abs(Guess*Guess/X - 1.0) > 3.0*Dummy'Epsilon loop
Guess := (X/Guess + Guess) * 0.5;
end loop;
return Guess;
end Sqrt;
I tested this routine with Vax Ada 83, which has types Float, Long_Float, and
Long_Long_Float. That last type gives at least 33 decimal digits of precision.
I instantiated this function, as well as Text_IO.Float_IO, for all three
types. When I tested with the three types, all displayed digits of the answers
were correct. I hereby place this long and complex function :-) into the
public domain. Enjoy.
- John Herro
You can download a shareware AdaTutor program at
http://members.aol.com/AdaTutor
next prev parent reply other threads:[~1999-03-24 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 ` 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 ` 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-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-24 0:00 ` John Herro [this message]
1999-03-24 0:00 ` Calculating SQRT in ADA 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 ` 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-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 ` 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-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