comp.lang.ada
 help / color / mirror / Atom feed
From: stt@spock.camb.inmet.com (Tucker Taft)
Subject: Re: 64 bit integer support as native type
Date: Fri, 23 Sep 1994 17:41:53 GMT
Date: 1994-09-23T17:41:53+00:00	[thread overview]
Message-ID: <CwLFtu.29H@inmet.camb.inmet.com> (raw)
In-Reply-To: 35setv$7nq@walters.east.sun.com

In article <35setv$7nq@walters.east.sun.com>,
Brent Slone <brent@paisley.East.Sun.COM> wrote:

>Does the Ada LRM define a 64 bit integer?  

Unlike C/C++, the language does not define any specific sizes,
though it does establish some minimums for Integer (and 
Long_Integer if defined).  Users who want an integer of a 
specific size should declare it themselves, such as:

    type Int_64 is range -2**63 .. +2**63-1;

Alternatively, they can rely on package Interfaces, which
has predeclared various useful sizes, such as Interfaces.Integer_64.
However, using Interfaces is less portable.
Note that if you want to be portable to one's complement machines,
or implementations that use the most negative value to represent
uninitialized (some versions of Rational), then the above should
be:

   type Int_64 is range -(2**63-1) .. +2**63-1;

To minimize the likelihood of software-imposed range checks.

   type Int_64_Constrained is range -(2**63-1) .. +2**63-1;
   subtype Int_64 is Int_64_Constrained'Base;

This will give you an unconstrained subtype which has at least
64 bits, but may have more.  Only overflow checks will be imposed
on such a subtype, never range checks.

> ... If not, what is the most
>straightforward method for implementing 64 bit ints?

There are many approaches to implementing 64 bit integers, given
implementations of 32 bits.  With the new "modular" integer types,
it is even easier:

    type Int_64 is private;
    function "+"(Left, Right: Int_64) return Int_64;
    function "-"(Left, Right: Int_64) return Int_64;
    ...
 private
    type Int_64 is record
       Low : Interfaces.Unsigned_32;
       High : Interfaces.Integer_32;
    end record;


To do a 64-bit add, you add the low parts, and check for
overflow (with unsigned numbers, overflow corresponds to 
the case where the result is less than one of the operands),
and then add the high parts, plus one more if the low parts overflowed.

Similar algorithms apply to the other operations.
As usual, Knuth has all of these algorithms spelled out
if you need them.

>Thanks,
>
>
>Brent Slone

S. Tucker Taft   stt@inmet.com
Intermetrics, Inc.
Cambridge, MA  02138
>





       reply	other threads:[~1994-09-23 17:41 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <35setv$7nq@walters.east.sun.com>
1994-09-23 17:41 ` Tucker Taft [this message]
1994-09-22 17:29 64 bit integer support as native type Brent Slone
1994-09-23 11:55 ` Robert I. Eachus
1994-09-23 15:34 ` Robert Dewar
1994-09-23 16:09 ` Norman H. Cohen
replies disabled

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