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=-0.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,68e7d264bfe3bcbf X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1994-09-23 11:01:42 PST Newsgroups: comp.lang.ada Path: bga.com!news.sprintlink.net!howland.reston.ans.net!noc.near.net!inmet!spock!stt From: stt@spock.camb.inmet.com (Tucker Taft) Subject: Re: 64 bit integer support as native type Message-ID: Sender: news@inmet.camb.inmet.com Organization: Intermetrics, Inc. References: <35setv$7nq@walters.east.sun.com> Date: Fri, 23 Sep 1994 17:41:53 GMT Date: 1994-09-23T17:41:53+00:00 List-Id: In article <35setv$7nq@walters.east.sun.com>, Brent Slone 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 >