comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <spam@spam.com>
Subject: Re: how to round integers (Figured it out!)
Date: Wed, 18 Jun 2003 18:07:52 GMT
Date: 2003-06-18T18:07:52+00:00	[thread overview]
Message-ID: <3EF0AA68.7020901@spam.com> (raw)
In-Reply-To: 3EF03178.9000908@attbi.com

Robert I. Eachus wrote:
> Jeffrey Carter wrote:
> 
>> Robert I. Eachus wrote:
>>
>>>   function Round is new Rounding(Integer);
>>
>> What happens in the case of negative arguments?
> 
> Oops!  New version for the new requirement. ;-) And if you think it is 
> messy, it is, that is the nature of division, as Intel and others have 
> found out. (It is actually the corner cases that are tricky--and you 
> really have to test all of them.)

Not really a new requirment. Your generic specification clearly allows 
instantiation with subtypes that include negative values (such as your 
instantiation with Integer), so clearly the function is intended to 
handle negative arguments :)

Yes, it is messy. So I would have made it a generic package, with the 
following declarations:

subtype Natural_Int  is Int range 0 .. Int'Last;
subtype Positive_Int is Int range 1 .. Int'Last;

function Rounding (Dividend : Natural_Int; Divisor : Positive_Int)
return Int;

Then your original algorithm would be fine.

-- 
Jeff Carter
"You tiny-brained wipers of other people's bottoms!"
Monty Python & the Holy Grail




  reply	other threads:[~2003-06-18 18:07 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-06-16  2:55 how to round integers Cephus�
2003-06-16  4:03 ` Charles LaCour
2003-06-16 12:12   ` Cephus�
2003-06-16 21:59   ` Jeffrey Creem
2003-06-16 10:09 ` Martin Dowie
2003-06-16 10:49 ` David C. Hoos
2003-06-16 12:18 ` how to round integers (Figured it out!) Cephus�
2003-06-16 12:34   ` David C. Hoos
2003-06-16 12:36     ` Cephus�
2003-06-16 13:12       ` David C. Hoos
2003-06-17  4:44         ` Robert I. Eachus
2003-06-17 19:20           ` Jeffrey Carter
2003-06-18  9:32             ` Robert I. Eachus
2003-06-18 18:07               ` Jeffrey Carter [this message]
2003-06-19  0:34                 ` Robert I. Eachus
2003-06-19 23:40                   ` Jeffrey Carter
replies disabled

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