comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <spam@spam.com>
Subject: Re: how to round integers (Figured it out!)
Date: Tue, 17 Jun 2003 19:20:01 GMT
Date: 2003-06-17T19:20:01+00:00	[thread overview]
Message-ID: <3EEF6A62.5010809@spam.com> (raw)
In-Reply-To: 3EEE9C81.7030904@attbi.com

Robert I. Eachus wrote:
>   function Rounding(Dividend, Divisor: Int) return Int is
>   begin
>     return (Dividend + Dividend + Divisor) / (Divisor + Divisor);
>   exception
>     when Constraint_Error =>
>       declare
>         Temp: Int;
>       begin
>         Temp := Dividend rem Divisor;
>         if Temp > Int'Last/2 or else Temp * 2 >= Divisor
>         then return Dividend/Divisor + 1;
>         -- Divisor is always less than or equal to Int'Last
>         else return Dividend/Divisor;
>         end if;
>       end;
>   end Rounding;
> 
>   function Round is new Rounding(Integer);

What happens in the case of negative arguments?

-- 
Jeff Carter
"C++ is like jamming a helicopter inside a Miata
and expecting some sort of improvement."
Drew Olbrich




  reply	other threads:[~2003-06-17 19:20 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 [this message]
2003-06-18  9:32             ` Robert I. Eachus
2003-06-18 18:07               ` Jeffrey Carter
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