Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Dammit Jim, I'm an actor, not a doctor.


devel / comp.lang.ada / Constraint error overflow

SubjectAuthor
* Constraint error overflowRichard Iswara
`* Re: Constraint error overflowDmitry A. Kazakov
 `* Re: Constraint error overflowRichard Iswara
  +- Re: Constraint error overflowMark Lorenzen
  +- Re: Constraint error overflowShark8
  +- Re: Constraint error overflowJeffrey R. Carter
  +* Re: Constraint error overflowDmitry A. Kazakov
  |`- Re: Constraint error overflowRichard Iswara
  `- Re: Constraint error overflowSimon Wright

1
Constraint error overflow

<e3861b0f-d8aa-4400-8842-8b16765991f0n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5120&group=comp.lang.ada#5120

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:a05:620a:4143:: with SMTP id k3mr22675087qko.497.1619532244187; Tue, 27 Apr 2021 07:04:04 -0700 (PDT)
X-Received: by 2002:a25:1883:: with SMTP id 125mr32094095yby.465.1619532243935; Tue, 27 Apr 2021 07:04:03 -0700 (PDT)
Path: i2pn2.org!i2pn.org!paganini.bofh.team!news.dns-netz.com!news.freedyn.net!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!tr2.eu1.usenetexpress.com!feeder.usenetexpress.com!tr2.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Tue, 27 Apr 2021 07:04:03 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=139.228.33.191; posting-account=oy9pPgoAAACICsEVtbydIrxpi9tsYOGl
NNTP-Posting-Host: 139.228.33.191
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <e3861b0f-d8aa-4400-8842-8b16765991f0n@googlegroups.com>
Subject: Constraint error overflow
From: haujekch...@gmail.com (Richard Iswara)
Injection-Date: Tue, 27 Apr 2021 14:04:04 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 32
 by: Richard Iswara - Tue, 27 Apr 2021 14:04 UTC

Ada beginner here. I was trying to multiply the first 100 integer and GNAT throw me a constraint error, overflow. I check the error was on integer 13. So what did I do wrong here?
Gnat CE 2020, Windows 10 Pro 64bit.
Here is the relevant program:

with Ada.Text_IO;
with Ada.Integer_Text_IO;

procedure Simple is
sum : Natural := 0;
mul : Natural := 1;

begin
Ada.Text_IO.Put ( "Sum of first 100 integer is :" );
Summing:
for I in 1 .. 100 loop
sum := sum + I;
end loop Summing;
Ada.Integer_Text_IO.Put ( sum );
Ada.Text_IO.New_Line;

Ada.Text_IO.Put ( "Multiple of the first 100 integer is :" );
Ada.Text_IO.New_Line;
Multiplying:
for J in 1 .. 100 loop
Ada.Integer_Text_IO.Put (J);
Ada.Text_IO.New_Line;
mul := mul * J;
end loop Multiplying;
Ada.Integer_Text_IO.Put ( mul );
Ada.Text_IO.New_Line;
end Simple;

Re: Constraint error overflow

<s698u1$bbr$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5121&group=comp.lang.ada#5121

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!aioe.org!5WHqCw2XxjHb2npjM9GYbw.user.gioia.aioe.org.POSTED!not-for-mail
From: mail...@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.ada
Subject: Re: Constraint error overflow
Date: Tue, 27 Apr 2021 17:00:20 +0200
Organization: Aioe.org NNTP Server
Lines: 11
Message-ID: <s698u1$bbr$1@gioia.aioe.org>
References: <e3861b0f-d8aa-4400-8842-8b16765991f0n@googlegroups.com>
NNTP-Posting-Host: 5WHqCw2XxjHb2npjM9GYbw.user.gioia.aioe.org
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Complaints-To: abuse@aioe.org
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.10.0
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Dmitry A. Kazakov - Tue, 27 Apr 2021 15:00 UTC

On 2021-04-27 16:04, Richard Iswara wrote:
> Ada beginner here. I was trying to multiply the first 100 integer and GNAT throw me a constraint error, overflow. I check the error was on integer 13. So what did I do wrong here?

Nothing, it is just so that

14! > 2**31 - 1

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

Re: Constraint error overflow

<be95bd99-dc1e-44ec-ac26-a2bacc1e8f86n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5122&group=comp.lang.ada#5122

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:ac8:7b27:: with SMTP id l7mr3178779qtu.302.1619537539091;
Tue, 27 Apr 2021 08:32:19 -0700 (PDT)
X-Received: by 2002:a25:6d02:: with SMTP id i2mr33766893ybc.309.1619537538901;
Tue, 27 Apr 2021 08:32:18 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.snarked.org!border2.nntp.dca1.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Tue, 27 Apr 2021 08:32:18 -0700 (PDT)
In-Reply-To: <s698u1$bbr$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=139.228.33.191; posting-account=oy9pPgoAAACICsEVtbydIrxpi9tsYOGl
NNTP-Posting-Host: 139.228.33.191
References: <e3861b0f-d8aa-4400-8842-8b16765991f0n@googlegroups.com> <s698u1$bbr$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <be95bd99-dc1e-44ec-ac26-a2bacc1e8f86n@googlegroups.com>
Subject: Re: Constraint error overflow
From: haujekch...@gmail.com (Richard Iswara)
Injection-Date: Tue, 27 Apr 2021 15:32:19 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 13
 by: Richard Iswara - Tue, 27 Apr 2021 15:32 UTC

On Tuesday, April 27, 2021 at 10:00:22 PM UTC+7, Dmitry A. Kazakov wrote:
> On 2021-04-27 16:04, Richard Iswara wrote:
> > Ada beginner here. I was trying to multiply the first 100 integer and GNAT throw me a constraint error, overflow. I check the error was on integer 13. So what did I do wrong here?
> Nothing, it is just so that
>
> 14! > 2**31 - 1
>
> --
> Regards,
> Dmitry A. Kazakov
> http://www.dmitry-kazakov.de

So the compiler is restricted to 32 bit integer value. I had hoped for 64 bit to get 18 digits.
Thank you.

Re: Constraint error overflow

<cd49715d-9bac-48cd-847c-1dba6705bec4n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5123&group=comp.lang.ada#5123

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:a05:622a:205:: with SMTP id b5mr22132377qtx.186.1619537934190;
Tue, 27 Apr 2021 08:38:54 -0700 (PDT)
X-Received: by 2002:a25:cf8e:: with SMTP id f136mr25293501ybg.462.1619537934048;
Tue, 27 Apr 2021 08:38:54 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Tue, 27 Apr 2021 08:38:53 -0700 (PDT)
In-Reply-To: <be95bd99-dc1e-44ec-ac26-a2bacc1e8f86n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=185.34.132.200; posting-account=Srm5lQoAAAAEMX9rv2ilEKR6FDPapmSq
NNTP-Posting-Host: 185.34.132.200
References: <e3861b0f-d8aa-4400-8842-8b16765991f0n@googlegroups.com>
<s698u1$bbr$1@gioia.aioe.org> <be95bd99-dc1e-44ec-ac26-a2bacc1e8f86n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <cd49715d-9bac-48cd-847c-1dba6705bec4n@googlegroups.com>
Subject: Re: Constraint error overflow
From: mark.lor...@gmail.com (Mark Lorenzen)
Injection-Date: Tue, 27 Apr 2021 15:38:54 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Mark Lorenzen - Tue, 27 Apr 2021 15:38 UTC

On Tuesday, April 27, 2021 at 5:32:20 PM UTC+2, haujek...@gmail.com wrote:
> So the compiler is restricted to 32 bit integer value. I had hoped for 64 bit to get 18 digits.
> Thank you.

Define your own type instead of relying on pre-defined types. Ada is not C.

Regards,
Mark L

Re: Constraint error overflow

<48671e5c-8e9d-41c1-9ebc-2b4de6e0ed29n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5124&group=comp.lang.ada#5124

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:ac8:70c1:: with SMTP id g1mr21750485qtp.147.1619538265083;
Tue, 27 Apr 2021 08:44:25 -0700 (PDT)
X-Received: by 2002:a25:424e:: with SMTP id p75mr18446578yba.161.1619538264928;
Tue, 27 Apr 2021 08:44:24 -0700 (PDT)
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!feeder1.cambriumusenet.nl!feed.tweak.nl!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Tue, 27 Apr 2021 08:44:24 -0700 (PDT)
In-Reply-To: <be95bd99-dc1e-44ec-ac26-a2bacc1e8f86n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=146.5.2.231; posting-account=lJ3JNwoAAAAQfH3VV9vttJLkThaxtTfC
NNTP-Posting-Host: 146.5.2.231
References: <e3861b0f-d8aa-4400-8842-8b16765991f0n@googlegroups.com>
<s698u1$bbr$1@gioia.aioe.org> <be95bd99-dc1e-44ec-ac26-a2bacc1e8f86n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <48671e5c-8e9d-41c1-9ebc-2b4de6e0ed29n@googlegroups.com>
Subject: Re: Constraint error overflow
From: onewinge...@gmail.com (Shark8)
Injection-Date: Tue, 27 Apr 2021 15:44:25 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Shark8 - Tue, 27 Apr 2021 15:44 UTC

On Tuesday, April 27, 2021 at 9:32:20 AM UTC-6, haujek wrote:
> So the compiler is restricted to 32 bit integer value. I had hoped for 64 bit to get 18 digits.

Depends on the compiler.
You can always model your domain more explicitly:
Bit_Size : Constant := 64;
Bit_First : Constant := 0;
Bit_Last : Constant := 2**Big_Bit_Size - 1;
Type Big_Integer_Test is range Bit_First..Bit_Last with Size => Bit_Size;

Function Factorial(Input:Big_Integer_Test) return Big_Integer_Test is
(case Input is
when 0 => 1,
when 1 | 2 => Input,
when others => Input * Factorial(Big_Integer_Test'Pred(Input))
);

Re: Constraint error overflow

<s69bvn$i9e$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5125&group=comp.lang.ada#5125

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: spam.jrc...@spam.not.acm.org (Jeffrey R. Carter)
Newsgroups: comp.lang.ada
Subject: Re: Constraint error overflow
Date: Tue, 27 Apr 2021 17:52:23 +0200
Organization: Also freenews.netfront.net; news.tornevall.net;
news.eternal-september.org
Lines: 13
Message-ID: <s69bvn$i9e$1@dont-email.me>
References: <e3861b0f-d8aa-4400-8842-8b16765991f0n@googlegroups.com>
<s698u1$bbr$1@gioia.aioe.org>
<be95bd99-dc1e-44ec-ac26-a2bacc1e8f86n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 27 Apr 2021 15:52:23 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="35fa0478e5561790154ea7d6f6714982";
logging-data="18734"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18gniJKTibBlcpwlUhGcx5Y0xURd7yfxyM="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.7.1
Cancel-Lock: sha1:dFwB2nJX9PC5ByDDYkeOD7ZpUeA=
In-Reply-To: <be95bd99-dc1e-44ec-ac26-a2bacc1e8f86n@googlegroups.com>
Content-Language: en-US
 by: Jeffrey R. Carter - Tue, 27 Apr 2021 15:52 UTC

On 4/27/21 5:32 PM, Richard Iswara wrote:
>
> So the compiler is restricted to 32 bit integer value. I had hoped for 64 bit to get 18 digits.

No, the compiler defines type Integer as 32 bits. You can define other types
with larger ranges. For trying to calculate 100!, even 64 bits is not enough;
you'd need to use an unbounded integer package.

--
Jeff Carter
"There's no messiah here. There's a mess all right, but no messiah."
Monty Python's Life of Brian
84

Re: Constraint error overflow

<s69cdq$796$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5126&group=comp.lang.ada#5126

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!aioe.org!5WHqCw2XxjHb2npjM9GYbw.user.gioia.aioe.org.POSTED!not-for-mail
From: mail...@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.ada
Subject: Re: Constraint error overflow
Date: Tue, 27 Apr 2021 17:59:57 +0200
Organization: Aioe.org NNTP Server
Lines: 19
Message-ID: <s69cdq$796$1@gioia.aioe.org>
References: <e3861b0f-d8aa-4400-8842-8b16765991f0n@googlegroups.com>
<s698u1$bbr$1@gioia.aioe.org>
<be95bd99-dc1e-44ec-ac26-a2bacc1e8f86n@googlegroups.com>
NNTP-Posting-Host: 5WHqCw2XxjHb2npjM9GYbw.user.gioia.aioe.org
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Complaints-To: abuse@aioe.org
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.10.0
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: Dmitry A. Kazakov - Tue, 27 Apr 2021 15:59 UTC

On 2021-04-27 17:32, Richard Iswara wrote:
> On Tuesday, April 27, 2021 at 10:00:22 PM UTC+7, Dmitry A. Kazakov wrote:
>> On 2021-04-27 16:04, Richard Iswara wrote:
>>> Ada beginner here. I was trying to multiply the first 100 integer and GNAT throw me a constraint error, overflow. I check the error was on integer 13. So what did I do wrong here?
>> Nothing, it is just so that
>>
>> 14! > 2**31 - 1

> So the compiler is restricted to 32 bit integer value. I had hoped for 64 bit to get 18 digits.

That won't give you 100! That is 158 digits or so.

Long_Float gamma function should do the trick, or arbitrary precision
integer arithmetic.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

Re: Constraint error overflow

<lyk0on8za0.fsf@pushface.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5127&group=comp.lang.ada#5127

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!aioe.org!yy9MKEJN2ULhWGfnfq4v5w.user.gioia.aioe.org.POSTED!not-for-mail
From: sim...@pushface.org (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
Lines: 49
Message-ID: <lyk0on8za0.fsf@pushface.org>
References: <e3861b0f-d8aa-4400-8842-8b16765991f0n@googlegroups.com>
<s698u1$bbr$1@gioia.aioe.org>
<be95bd99-dc1e-44ec-ac26-a2bacc1e8f86n@googlegroups.com>
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=
 by: Simon Wright - Tue, 27 Apr 2021 16:31 UTC

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

Re: Constraint error overflow

<d7d88cf0-91cb-473d-bad0-fb024b6b7a61n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=5129&group=comp.lang.ada#5129

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:ac8:6703:: with SMTP id e3mr25176798qtp.247.1619593430480;
Wed, 28 Apr 2021 00:03:50 -0700 (PDT)
X-Received: by 2002:a25:9c86:: with SMTP id y6mr7066728ybo.405.1619593430247;
Wed, 28 Apr 2021 00:03:50 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Wed, 28 Apr 2021 00:03:50 -0700 (PDT)
In-Reply-To: <s69cdq$796$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=36.85.88.151; posting-account=oy9pPgoAAACICsEVtbydIrxpi9tsYOGl
NNTP-Posting-Host: 36.85.88.151
References: <e3861b0f-d8aa-4400-8842-8b16765991f0n@googlegroups.com>
<s698u1$bbr$1@gioia.aioe.org> <be95bd99-dc1e-44ec-ac26-a2bacc1e8f86n@googlegroups.com>
<s69cdq$796$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <d7d88cf0-91cb-473d-bad0-fb024b6b7a61n@googlegroups.com>
Subject: Re: Constraint error overflow
From: haujekch...@gmail.com (Richard Iswara)
Injection-Date: Wed, 28 Apr 2021 07:03:50 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Richard Iswara - Wed, 28 Apr 2021 07:03 UTC

On Tuesday, April 27, 2021 at 10:59:57 PM UTC+7, Dmitry A. Kazakov wrote:
> On 2021-04-27 17:32, Richard Iswara wrote:
> > On Tuesday, April 27, 2021 at 10:00:22 PM UTC+7, Dmitry A. Kazakov wrote:
> >> On 2021-04-27 16:04, Richard Iswara wrote:
> >>> Ada beginner here. I was trying to multiply the first 100 integer and GNAT throw me a constraint error, overflow. I check the error was on integer 13. So what did I do wrong here?
> >> Nothing, it is just so that
> >>
> >> 14! > 2**31 - 1
> > So the compiler is restricted to 32 bit integer value. I had hoped for 64 bit to get 18 digits.
> That won't give you 100! That is 158 digits or so.
>
> Long_Float gamma function should do the trick, or arbitrary precision
> integer arithmetic.
> --
> Regards,
> Dmitry A. Kazakov
> http://www.dmitry-kazakov.de

Thank you all of you who responded and give very helpful advices. i am very much an amateur beginner in programming . .

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor