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,5b88cd8e97eaef79,start X-Google-Attributes: gid103376,public From: "W. Wesley Groleau (Wes)" Subject: Integer Square Root Date: 1996/10/15 Message-ID: <9610152208.AA14714@most>#1/1 X-Deja-AN: 189717463 sender: Ada programming language comments: To: mheaney@ni.net mailer: Elm [revision: 70.85] newsgroups: comp.lang.ada Date: 1996-10-15T00:00:00+00:00 List-Id: I meant to post this a long time ago. Sorry about the delay. M. Heaney's integer square root algorithm should not be used without testing. After applying the correction he posted, here's how it performs: If the input is zero or one, a divide by zero exception is raised. (constraint_error) perfect square: If the input is N*N where N is any integer greater than one, the answer is correct (after applying the correction you posted). perfect square minus one: For the same N, an input of N*N-1 never terminates. For all other positive integers, the answer is equivalent to the float answer with the fractional part truncated, i.e., root 62 comes out 7 where integer(sqrt(float(62))) would be 8. (Some people may prefer truncation). For negative numbers, sometimes it produces an answer (possibly a negative answer), sometimes it doesn't terminate, sometimes it raises the exception. --------------------------------------------------------------------------- W. Wesley Groleau (Wes) Office: 219-429-4923 Hughes Defense Communications (MS 10-40) Home: 219-471-7206 Fort Wayne, IN 46808 (Unix): wwgrol@pseserv3.fw.hac.com ---------------------------------------------------------------------------