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,FREEMAIL_FROM autolearn=ham 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 04:49:13 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsmm00.sul.t-online.com!t-online.de!news.t-online.com!not-for-mail From: "Lars" Newsgroups: comp.lang.ada Subject: Re: Modular integers Date: Tue, 28 Oct 2003 13:48:22 +0100 Organization: T-Online Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: news.t-online.com 1067345250 03 26733 -RpNVthGSPHcCa 031028 12:47:30 X-Complaints-To: usenet-abuse@t-online.de X-ID: rBn9ocZJYe6rztRbtkmJWekz8MRkl2Z2VHsyJnMq6mnTDK1zRllnYc X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Xref: archiver1.google.com comp.lang.ada:1768 Date: 2003-10-28T13:48:22+01:00 List-Id: Yes, it is not "reset". I don't know a better word to describe it ... 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 ... > 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).