comp.lang.ada
 help / color / mirror / Atom feed
From: "W. Wesley Groleau (Wes)" <wwgrol@PSESERV3.FW.HAC.COM>
Subject: Integer Square Root
Date: 1996/10/15
Date: 1996-10-15T00:00:00+00:00	[thread overview]
Message-ID: <9610152208.AA14714@most> (raw)


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
---------------------------------------------------------------------------




             reply	other threads:[~1996-10-15  0:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-10-15  0:00 W. Wesley Groleau (Wes) [this message]
  -- strict thread matches above, loose matches on Subject: below --
1996-10-15  0:00 Integer Square Root Matthew Heaney
1996-10-17  0:00 ` Mats Weber
1996-10-17  0:00 ` Keith Thompson
1996-10-17  0:00   ` Matthew Heaney
1996-10-22  0:00     ` Oliver Kellogg
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox