comp.lang.ada
 help / color / mirror / Atom feed
From: Robert Eachus <rieachus@comcast.net>
Subject: Re: 64-bit unsigned integer?
Date: Sun, 25 Feb 2018 22:45:24 -0800 (PST)
Date: 2018-02-25T22:45:24-08:00	[thread overview]
Message-ID: <001e93f1-b645-4312-8a29-caca3860b560@googlegroups.com> (raw)
In-Reply-To: <e8c6d243-b919-4fc5-a6dc-aeb5e2042be9@googlegroups.com>

On Sunday, February 25, 2018 at 7:30:59 AM UTC-5, MM wrote:
> Hi
> 
> I'm trying to get an unsigned integer type of 64 bits without modular wraparound.
> 
> On the GNAT that I have on my OSX, v7.1.0, I have experimented a bit, and can't get it right.
> 
> I can declare the type
> 
> type u64 is mod 2**64; -- this gives the range of numbers I want, but wraps if It overflows.

The package that Dmitry is a nice workaround if you really need that particular type.  Decades ago, there was a problem in Ada 83 that you couldn't define 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 there are places where the unconstrained type (not the subtype) shows up, and they 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 they 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 that playing with the arithmetic is only needed for the largest representable integer type.  Represent 0 by -128 and 255 by 127, and do the obvious correction 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 definition, the workaround means that another fix seems unnecessary.  Modular types were worth adding for lots of other reasons--I've used them for indexes to hash tables all over the place.


  parent reply	other threads:[~2018-02-26  6:45 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-25 12:30 64-bit unsigned integer? MM
2018-02-25 12:41 ` Dmitry A. Kazakov
2018-02-25 12:54   ` MM
2018-02-25 13:23     ` Dmitry A. Kazakov
2018-02-25 13:59       ` MM
2018-02-25 14:20         ` Dmitry A. Kazakov
2018-02-25 15:34           ` MM
2018-02-25 16:35     ` Jeffrey R. Carter
2018-02-25 16:36 ` Anh Vo
2018-02-25 17:31   ` MM
2018-02-26 23:19     ` Randy Brukardt
2018-02-26 23:33       ` MM
2018-02-28 10:17       ` Paul Rubin
2018-02-28 10:39         ` J-P. Rosen
2018-02-28 10:59           ` Dmitry A. Kazakov
2018-02-28 23:20         ` Randy Brukardt
2018-03-01  5:47           ` Paul Rubin
2018-03-01  8:16             ` Niklas Holsti
2018-03-01  8:35               ` Simon Wright
2018-03-01  8:47               ` Dmitry A. Kazakov
2018-03-01 18:15                 ` Dan'l Miller
2018-03-01 19:10                   ` Dmitry A. Kazakov
2018-03-01 19:22                     ` Dan'l Miller
2018-03-01 19:59                       ` Dmitry A. Kazakov
2018-03-01 20:32                         ` Dan'l Miller
2018-03-01 21:15                           ` Dmitry A. Kazakov
2018-03-01 22:23                             ` Randy Brukardt
2018-03-01 23:50                             ` Robert Eachus
2018-03-01 20:06                     ` Niklas Holsti
2018-03-01 22:04               ` Randy Brukardt
2018-02-26  6:45 ` Robert Eachus [this message]
2018-02-27 16:40   ` Dan'l Miller
2018-02-27 17:18     ` J-P. Rosen
2018-02-27 18:17       ` Dan'l Miller
2018-02-28  3:03         ` Robert Eachus
2018-02-28  6:41         ` J-P. Rosen
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox