From: Simon Wright <simon@pushface.org>
Subject: Re: Constraint error overflow
Date: Tue, 27 Apr 2021 17:31:35 +0100 [thread overview]
Message-ID: <lyk0on8za0.fsf@pushface.org> (raw)
In-Reply-To: be95bd99-dc1e-44ec-ac26-a2bacc1e8f86n@googlegroups.com
Richard Iswara <haujekchifan@gmail.com> writes:
> So the compiler is restricted to 32 bit integer value. I had hoped for
> 64 bit to get 18 digits.
GNAT comes with Long_Integer (64 bits).
Or yu could go with the Ada202x Big_Integers package
(http://www.ada-auth.org/standards/2xrm/html/RM-A-5-6.html),
pragma Ada_2020;
with Ada.Text_IO;
with Ada.Numerics.Big_Numbers.Big_Integers;
procedure Iswara is
use Ada.Numerics.Big_Numbers.Big_Integers;
Sum : Big_Natural := 0;
Mul : Big_Natural := 1;
begin
Ada.Text_IO.Put ( "Sum of the first 100 integers is :" );
Ada.Text_IO.New_Line;
Summing:
for I in 1 .. 100 loop
Sum := Sum + To_Big_Integer (I);
end loop Summing;
Ada.Text_IO.Put ( Sum'Image );
Ada.Text_IO.New_Line;
Ada.Text_IO.Put ( "Multiple of the first 100 integers is :" );
Ada.Text_IO.New_Line;
Multiplying:
for J in 1 .. 100 loop
Mul := Mul * To_Big_Integer (J);
end loop Multiplying;
Ada.Text_IO.Put ( Mul'Image );
Ada.Text_IO.New_Line;
end Iswara;
which compiles fine with GNAT CE 2020 & FSF GCC 11.0.1; result
$ ./iswara
Sum of the first 100 integers is :
5050
Multiple of the first 100 integers is :
93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000
prev parent reply other threads:[~2021-04-27 16:31 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-27 14:04 Constraint error overflow Richard Iswara
2021-04-27 15:00 ` Dmitry A. Kazakov
2021-04-27 15:32 ` Richard Iswara
2021-04-27 15:38 ` Mark Lorenzen
2021-04-27 15:44 ` Shark8
2021-04-27 15:52 ` Jeffrey R. Carter
2021-04-27 15:59 ` Dmitry A. Kazakov
2021-04-28 7:03 ` Richard Iswara
2021-04-27 16:31 ` Simon Wright [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox