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=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,32c6d2fb891775fc X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-10-28 10:52:07 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!news.agarik.com!news.agarik.com!usenet-fr.net!enst.fr!melchior!cuivre.fr.eu.org!melchior.frmug.org!not-for-mail From: "David C. Hoos" Newsgroups: comp.lang.ada Subject: Re: Modular integers Date: Tue, 28 Oct 2003 12:50:05 -0600 Organization: Cuivre, Argent, Or Message-ID: References: NNTP-Posting-Host: lovelace.ada-france.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Trace: melchior.cuivre.fr.eu.org 1067367051 99206 80.67.180.195 (28 Oct 2003 18:50:51 GMT) X-Complaints-To: usenet@melchior.cuivre.fr.eu.org NNTP-Posting-Date: Tue, 28 Oct 2003 18:50:51 +0000 (UTC) To: "Lars" , "comp.lang.ada@ada.eu.org" Return-Path: X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 X-Virus-Scanned: by amavisd-new-20030616-p5 (Debian) at ada-france.org X-BeenThere: comp.lang.ada@ada-france.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Gateway to the comp.lang.ada Usenet newsgroup List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Xref: archiver1.google.com comp.lang.ada:1785 Date: 2003-10-28T12:50:05-06:00 "Lars" wrote in message news:bnloh2$q3d$03$1@news.t-online.com... > Yes, it is not "reset". I don't know a better word to describe it ... How about "wraps" or "wraps around"? > > Why couldn't the compiler insert code that checks what the upper limit of > the type is, then substracts the current value of the variable from the > upper limit to see if the difference is bigger or equal to the number you > want to add? If it is not, it could throw an exception ... It cannot raise an exception because the langeage definition (RM95 3.5.4) defines a modular type as one in which all arithmetic is _modulo_ the specified modulus -- i.e. with "wrap-around" semantics. > > > > No. By definition modular numbers cannot "overflow." In fact, to say the > > value > > is "reset" to 0 is incorrect. 0 simply follows 2**64 - 1. > > > > You can declare a _signed_ 64-bit integer type which will overflow when > > adding > > 1 to 2**63-1, or underflow when subtracting 1 from -(2**63). > > > _______________________________________________ > comp.lang.ada mailing list > comp.lang.ada@ada-france.org > http://www.ada-france.org/mailman/listinfo/comp.lang.ada >