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,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,c0fe3a04fa2416f1 X-Google-Attributes: gid103376,public From: kst@thomsoft.com (Keith Thompson) Subject: Re: Ada function sqrt(x) Date: 1996/09/20 Message-ID: #1/1 X-Deja-AN: 184141163 sender: news@thomsoft.com (USENET News Admin @flash) x-nntp-posting-host: pulsar references: <01bba50c$7c1a2760$dc014dc6@MountainNet> <51o7nh$5vl@cf01> organization: Thomson Software Products, San Diego, CA, USA newsgroups: comp.lang.ada originator: kst@pulsar Date: 1996-09-20T00:00:00+00:00 List-Id: In <51o7nh$5vl@cf01> pascal.obry@der.edfgdf.fr (Pascal Obry) writes: > "zeppelin" wrote: > > >I want to find the sqrt of a interger... how can I do this and what package > >do I need to declare [...] > If you are using Ada95 then the package is > > Ada.Numerics.Generic_Elementary_Functions or > Ada.Numerics.Elementary_Functions (for a float instanciation). The original question was about finding the square root of an *integer*; Generic_Elementary_Functions and its instantiations work on floating-point types. You can convert the argument to a floating-point type, take the square root, and convert back to an integer type, but that may lose precision in some cases. Also, I think an integer square root operation typically truncates rather than rounding (for example, sqrt(99) is 9, not 10). Ada 95 provides a 'Truncation attribute (see RM95-A.5.3) -- but again, watch out for loss of precision (sqrt(9.0) *might* return something like 2.9999999; also, many 32-bit integers cannot be represented exactly in 32-bit floating-point). You might have better luck writing an integer sqrt function that only uses integer arithmetic. I'm sure this has been done before; perhaps someone else knows where. -- Keith Thompson (The_Other_Keith) kst@thomsoft.com <*> TeleSoft^H^H^H^H^H^H^H^H Alsys^H^H^H^H^H Thomson Software Products 10251 Vista Sorrento Parkway, Suite 300, San Diego, CA, USA, 92121-2706 FIJAGDWOL