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/24 Message-ID: <19990324125518.01416.00000432@ngol08.aol.com>#1/1 X-Deja-AN: 458494091 References: <36F913E0.75F51763@lmco.com> X-Admin: news@aol.com Organization: AOL http://www.aol.com Newsgroups: comp.lang.ada Date: 1999-03-24T00:00:00+00:00 List-Id: 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