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,32c6d2fb891775fc X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-10-28 04:28:41 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!wn14feed!worldnet.att.net!199.45.49.37!cyclone1.gnilink.net!peer01.cox.net!cox.net!bigfeed.bellsouth.net!bignumb.bellsouth.net!news.bellsouth.net!bignews5.bellsouth.net.POSTED!not-for-mail From: "David C. Hoos" Newsgroups: comp.lang.ada References: Subject: Re: Modular integers MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Message-ID: X-Trace: ldjgbllpbapjglppdbdpiflmbcekedmfhojhikkbagflhcbopglppmihfnbdlnjijcepmhenojdjhfmihmlgplcigbaoionphlbjpbippnceoinffpincbmbokiijioiopppfolbjlnaobhlogpjodebaikdkmoj NNTP-Posting-Date: Tue, 28 Oct 2003 07:26:23 EST Date: Tue, 28 Oct 2003 06:28:29 -0600 Xref: archiver1.google.com comp.lang.ada:1767 Date: 2003-10-28T06:28:29-06:00 List-Id: "Lars" wrote in message news:bnlmg1$kqv$04$1@news.t-online.com... > Hi, > > I was able to create an unsigned 64-bit integer using > > type unsigned_64_bit_integer is mod 2**64; > > Then I defined a subtype: > > subtype safe_unsigned_64_bit_integer is unsigned_64_bit_integer range 0 > .. 2**64-1; > > When a variable of type unsigned_64_bit_integer contains 2**64-1 and you add > 1, it is "reset" to 0, as expected. > When a variable of type safe_unsigned_64_bit_integer contains 2**64-1 and > you add 1, no exception is raised and it is "reset" to 0. > > Why is that? Shouldn't the compiler be able to insert a check that throws an > exception if an overflow occurs? 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). > > -Lars > > > _______________________________________________ > comp.lang.ada mailing list > comp.lang.ada@ada-france.org > http://www.ada-france.org/mailman/listinfo/comp.lang.ada > >