From: mheaney@ni.net (Matthew Heaney)
Subject: Re: Integer Square Root
Date: 1996/10/17
Date: 1996-10-17T00:00:00+00:00 [thread overview]
Message-ID: <mheaney-ya023180001710962222450001@news.ni.net> (raw)
In-Reply-To: DzEEq3.9tI@thomsoft.com
In article <DzEEq3.9tI@thomsoft.com>, kst@thomsoft.com (Keith Thompson) wrote:
>> function Square_Root (N : Natural) return Natural is
>[...]
>
>Sorry, but this still doesn't work. It says the square root of 6 is 3.
>If it's supposed to truncate, Square_Root(6) should return 2; if it's
>supposed to round, sqrt(6.0) = 2.4495 (approximately), so Square_Root(6)
>should still return 2. It also doesn't always return increasing values
>for increasing numbers; Square_Root(135) returns 12 and Square_Root(136)
>returns 11.
Well, yes and no. I intentionally wrote the return statement in the others
branch to be a "don't care"; it wasn't "supposed" to be truncation or
rounding. However, there are obvious virtues to having a continuously
increasing square root function!
If you want truncation behavior, the modification is simple:
return Natural'Min (X0, X1);
For rounding behavior,
return Natural'Max (X0, X1);
Perhaps I should have stated the behavior explicitly; thank you for
pointing this out.
--------------------------------------------------------------------
Matthew Heaney
Software Development Consultant
mheaney@ni.net
(818) 985-1271
next prev parent reply other threads:[~1996-10-17 0:00 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
1996-10-22 0:00 ` Oliver Kellogg
-- strict thread matches above, loose matches on Subject: below --
1996-10-15 0:00 W. Wesley Groleau (Wes)
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox