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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!nntp-feed.chiark.greenend.org.uk!ewrotcd!newsfeed.xs3.de!io.xs3.de!news.jacob-sparre.dk!franka.jacob-sparre.dk!pnx.dk!.POSTED.rrsoftware.com!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: 64-bit unsigned integer? Date: Mon, 26 Feb 2018 17:19:21 -0600 Organization: JSA Research & Innovation Message-ID: References: <421d1598-68d7-4d0b-b596-6e9c59cf865c@googlegroups.com> Injection-Date: Mon, 26 Feb 2018 23:19:22 -0000 (UTC) Injection-Info: franka.jacob-sparre.dk; posting-host="rrsoftware.com:24.196.82.226"; logging-data="2794"; mail-complaints-to="news@jacob-sparre.dk" X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246 Xref: reader02.eternal-september.org comp.lang.ada:50670 Date: 2018-02-26T17:19:21-06:00 List-Id: "MM" wrote in message news:a0147c10-775c-49bf-a0e7-2091f31ac11a@googlegroups.com... > On Sunday, 25 February 2018 16:36:47 UTC, Anh Vo wrote: >> On Sunday, February 25, 2018 at 4:30:59 AM UTC-8, MM wrote: >> > I tried >> > >> > type u64 is range 0 .. 2**64-1; -- this fails with "integer type >> > definition bounds out of range". >> > >> >> It should be: type u64 is range 0 .. 2 **63 - 1; > > That is a 63-bit unsigned, no? > >> This is max that GNAT can support on 64 bit architecture. > > Apparently :-) This is a language limitation. That's because U64'Base is always legal, and it has a symmetric signed range. Thus you need the signed values even if you never intent to use them. >> > 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? There's not the least bit of difficulty supporting such a thing; the Janus/Ada code generator has the needed operations and code generation (for 32-bit types, no 64-bit integers yet). I'd suspect that the same is true of many other code generators. The problem is simply one of language definition; there is no way in the Ada language to get overflow for an unsigned type. Therefore, you can have overflow on unsigned representation only so long as there is a (larger) signed representation available. (For instance, an overflowing unsigned byte representation is fine, as it can use a 16-bit signed base type). This limitation has always bothered me, but it never has been considered important enough to address in the language. These days, we're moving away from adding any more kinds of types; everything new will be a library much like the containers or the one Dmitry showed. (The reason being that we then don't need to define new kinds of generic types.) So I doubt the underlying issue will ever be changed. Randy.