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=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.107.181.20 with SMTP id e20mr6087428iof.43.1519563248596; Sun, 25 Feb 2018 04:54:08 -0800 (PST) X-Received: by 10.157.11.165 with SMTP id 34mr67883oth.7.1519563248483; Sun, 25 Feb 2018 04:54:08 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!nntp.giganews.com!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.am4!peer.am4.highwinds-media.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!o66no1482579ita.0!news-out.google.com!a25ni505itj.0!nntp.google.com!o66no1482577ita.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sun, 25 Feb 2018 04:54:08 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=2001:470:9174:2:d11c:9c25:268f:5457; posting-account=r0RePAgAAABkc8iAou09Mtfbf-fnKQql NNTP-Posting-Host: 2001:470:9174:2:d11c:9c25:268f:5457 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <63f986fd-662a-47e7-adf9-5fddc243ac45@googlegroups.com> Subject: Re: 64-bit unsigned integer? From: MM Injection-Date: Sun, 25 Feb 2018 12:54:08 +0000 Content-Type: text/plain; charset="UTF-8" X-Received-Body-CRC: 2590393323 X-Received-Bytes: 2364 Xref: reader02.eternal-september.org comp.lang.ada:50634 Date: 2018-02-25T04:54:08-08:00 List-Id: On Sunday, 25 February 2018 12:42:00 UTC, Dmitry Kazakov wrote: > On 2018-02-25 13:30, MM wrote: > > type u64 is range 0 .. 2**64-1; -- this fails with "integer type definition bounds out of range". > > This is the right method alas not supported by the architecture of the > machine you have. Damn. Its a 64-bit CPU; I would have thought that a Carry Or Overflow bit in the processor would have done the trick? > > Is there a way to do it so can get an unsigned integer that will raise an > > exception if it overflows? > > You must implement it yourself, e.g. on top of a modular or integer > type, or use an arbitrary length integer arithmetic package. There exist > a few in Ada. I don't want to go the BigNum route - too heavyweight. Implementing it efficiently myself may require access to the processor's condition code registers, so this feels like an assembly language approach? I could overload the arithmetic operators, but this feels icky, particularly given that regular signed 32- and 64-bit integers overflow "properly", i.e. with an exception. M --