From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Path: eternal-september.org!reader02.eternal-september.org!aioe.org!yy9MKEJN2ULhWGfnfq4v5w.user.gioia.aioe.org.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Constraint error overflow Date: Tue, 27 Apr 2021 17:31:35 +0100 Organization: Aioe.org NNTP Server Message-ID: References: NNTP-Posting-Host: yy9MKEJN2ULhWGfnfq4v5w.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain X-Complaints-To: abuse@aioe.org User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (darwin) X-Notice: Filtered by postfilter v. 0.9.2 Cancel-Lock: sha1:5fecISmGJxO1blTCp5U1/lXWyFY= Xref: reader02.eternal-september.org comp.lang.ada:61922 List-Id: Richard Iswara 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