From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,efbbbab26bad9cb X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-06-17 12:22:22 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!newshub.sdsu.edu!elnk-pas-nf2!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread1.prod.itd.earthlink.net.POSTED!not-for-mail Message-ID: <3EEF6A62.5010809@spam.com> From: Jeffrey Carter Organization: jrcarter commercial-at acm [period | full stop] org User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.0.0) Gecko/20020530 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: how to round integers (Figured it out!) References: <3EEE9C81.7030904@attbi.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Date: Tue, 17 Jun 2003 19:20:01 GMT NNTP-Posting-Host: 63.184.8.140 X-Complaints-To: abuse@earthlink.net X-Trace: newsread1.prod.itd.earthlink.net 1055877601 63.184.8.140 (Tue, 17 Jun 2003 12:20:01 PDT) NNTP-Posting-Date: Tue, 17 Jun 2003 12:20:01 PDT Xref: archiver1.google.com comp.lang.ada:39360 Date: 2003-06-17T19:20:01+00:00 List-Id: 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