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.198.65 with SMTP id w62mr8025636iof.105.1519627524777; Sun, 25 Feb 2018 22:45:24 -0800 (PST) X-Received: by 10.157.22.195 with SMTP id s3mr431791ots.13.1519627524701; Sun, 25 Feb 2018 22:45:24 -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!peer01.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!o66no1742994ita.0!news-out.google.com!10ni2509ite.0!nntp.google.com!o66no1742993ita.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sun, 25 Feb 2018 22:45:24 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=2601:191:8303:2100:7466:f44c:da21:40b1; posting-account=fdRd8woAAADTIlxCu9FgvDrUK4wPzvy3 NNTP-Posting-Host: 2601:191:8303:2100:7466:f44c:da21:40b1 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <001e93f1-b645-4312-8a29-caca3860b560@googlegroups.com> Subject: Re: 64-bit unsigned integer? From: Robert Eachus Injection-Date: Mon, 26 Feb 2018 06:45:24 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Received-Body-CRC: 1676381834 X-Received-Bytes: 3160 Xref: reader02.eternal-september.org comp.lang.ada:50646 Date: 2018-02-25T22:45:24-08:00 List-Id: On Sunday, February 25, 2018 at 7:30:59 AM UTC-5, MM wrote: > Hi >=20 > I'm trying to get an unsigned integer type of 64 bits without modular wra= paround. >=20 > On the GNAT that I have on my OSX, v7.1.0, I have experimented a bit, and= can't get it right. >=20 > I can declare the type >=20 > type u64 is mod 2**64; -- this gives the range of numbers I want, but wra= ps if It overflows. The package that Dmitry is a nice workaround if you really need that partic= ular type. Decades ago, there was a problem in Ada 83 that you couldn't de= fine a type with the normal modular properties for the largest integer type= in number of bits. Why? I'd have to go digging through old AIs, but ther= e are places where the unconstrained type (not the subtype) shows up, and t= hey need that one extra bit. In Ada 95 modular types were introduced to fix this problem. For embedded = systems that was great, there are many hardware registers in various pieces= of equipment, and the all usually work with wrap-around semantics. If the= y overflow instead? Define a signed type, and if you have a counter starts= at 0 and overflows? Go sort of backwards from Dmitry's solution. Notice t= hat playing with the arithmetic is only needed for the largest representabl= e integer type. Represent 0 by -128 and 255 by 127, and do the obvious cor= rection when reading the sensor into a larger computer register. There is = probably more work to convert the reading to a temperature or whatever, and= you can do it all in one place. Compared to trying to force fit a fix through a change in the language defi= nition, the workaround means that another fix seems unnecessary. Modular t= ypes were worth adding for lots of other reasons--I've used them for indexe= s to hash tables all over the place.