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-18 11:07:50 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!headwall.stanford.edu!newshub.sdsu.edu!elnk-pas-nf2!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread2.prod.itd.earthlink.net.POSTED!not-for-mail Message-ID: <3EF0AA68.7020901@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> <3EEF6A62.5010809@spam.com> <3EF03178.9000908@attbi.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Date: Wed, 18 Jun 2003 18:07:52 GMT NNTP-Posting-Host: 63.184.9.29 X-Complaints-To: abuse@earthlink.net X-Trace: newsread2.prod.itd.earthlink.net 1055959672 63.184.9.29 (Wed, 18 Jun 2003 11:07:52 PDT) NNTP-Posting-Date: Wed, 18 Jun 2003 11:07:52 PDT Xref: archiver1.google.com comp.lang.ada:39406 Date: 2003-06-18T18:07:52+00:00 List-Id: 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