From: "David C. Hoos" <david.c.hoos.sr@ada95.com>
Subject: Re: how to round integers (Figured it out!)
Date: Mon, 16 Jun 2003 08:12:40 -0500
Date: 2003-06-16T08:12:40-05:00 [thread overview]
Message-ID: <vergibdfn1hr44@corp.supernews.com> (raw)
In-Reply-To: vereehn58o9be1@corp.supernews.com
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 940 bytes --]
You are quite right. I was thinking of the algorithm which always
rounds up if there is any remainder -- e.g., if you need to know how
many boxes are required to ship N items, if M items will fit in a box.
The algorithm you need (which will do the job without any comparisons
and conditional operations is
(Dividend + Dividend + Divisor) / (Divisor + Divisor)
"Cephus�" <beau@hiwaay.net> wrote in message
news:vereehn58o9be1@corp.supernews.com...
>
>
> David C. Hoos wrote:
> > It's simpler to just add one less than the divisor to the dividend
> > before dividing.
>
>
> well look at if the total is 25. in your example, 25+3-1 = 27. That would
> give you 27/3 = 9
>
> but it is really 25/3 which equals 8 remainder 1 which is not enough to
> round up...
>
> Beau
>
>
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada.eu.org
> http://ada.eu.org/mailman/listinfo/comp.lang.ada
>
next prev parent reply other threads:[~2003-06-16 13:12 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 [this message]
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
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