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: dewar@cs.nyu.edu (Robert Dewar) Subject: Re: Ada function sqrt(x) Date: 1996/09/21 Message-ID: #1/1 X-Deja-AN: 184488548 references: <01bba50c$7c1a2760$dc014dc6@MountainNet> <51o7nh$5vl@cf01> organization: Courant Institute of Mathematical Sciences newsgroups: comp.lang.ada Date: 1996-09-21T00:00:00+00:00 List-Id: I assume the integer square root problem was an assignment anyway, so I am not about to provide the obvious answer, but Keith said "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)." In fact, the square root of 9 must be exactly 3. dp