comp.lang.ada
 help / color / mirror / Atom feed
From: Niklas Holsti <niklas.holsti@tidorum.invalid>
Subject: Re: Ada.Numerics.Big_Numbers.Big_Integer has a limit of 300 digits?
Date: Wed, 22 Dec 2021 21:05:18 +0200	[thread overview]
Message-ID: <j2hb7eFd05oU1@mid.individual.net> (raw)
In-Reply-To: <41879a68-95cf-41e7-a582-4358a39f9d47n@googlegroups.com>

On 2021-12-22 20:02, Michael Ferguson wrote:
> On Wednesday, December 22, 2021 at 11:48:46 AM UTC-6, Niklas Holsti
> wrote:
>> On 2021-12-22 19:27, Michael Ferguson wrote:
>>> On Wednesday, December 22, 2021 at 11:02:03 AM UTC-6, Luke A.
>>> Guest wrote:
>>>> On 22/12/2021 05:57, Michael Ferguson wrote:
>>>>> I just started using the Big_Integer library that is a part
>>>>> of the 202X version of ADA.
>>>>> 


    [snip]


> Not 100% sure what modular types are


Types declared with "mod N" instead of "range A .. B", as in:

    type Eight_Bits is mod 256;

which declares an unsigned type with a range 0 .. 255 and wrap-around
arithmetic.

Modular types are not connected to Big_Integers, except that the
particular problem you are trying to solve could be computed "mod 
10**10" because it asks for only the last 10 digits. However, the 
Big_Integers package does not directly support computations "mod" 
something (perhaps this should be an extension in a later Ada standard, 
because such computations are quite common).

Using "mod 10**10" operations in solving the problem would limit the
number of digits in all intermediate results drastically.


> but I did try to do something like the following
> 
> subtype VeryBigInteger is Big_Integer range 0 .. 10E10000;
> 
> which gave "error: incorrect constraint for this kind of type"


Indeed, such a range constraint is valid only for (visibly) scalar
types, which Big_Integer is not (it is a private type).


> Niklas also gave me an epiphany as the exact error my program gives
> for the upper limit is
> 
> raised STORAGE_ERROR :
> Ada.Numerics.Big_Numbers.Big_Integers.Bignums.Normalize: big integer
> limit exceeded
> 
> I had thought that since the end of this error said big integer limit
> exceeded it was a problem with the library, but now I'm starting to
> think I need to get GNAT to allocated more memory for the program.


Perhaps. However, the very specific exception message ("big integer 
limit exceeded") suggests that this exception is not a typical 
Storage_Error (say, heap or stack exhaustion) but may indeed stem from 
exceeding some specific limit in the current Big_Integer implementation 
in GNAT.

The size of your problem, with only a few thousand digits, suggests that 
heap exhaustion is unlikely to happen. However, if the Big_Integer 
computations are internally recursive, and use stack-allocated local 
variables, stack overflow could happen, so the first thing to try would 
be to increase the stack size. Unfortunately, for the main subprogram 
that has to be done with some compiler or linker options which I don't 
recall now. (We should really extend pragma Storage_Size to apply also 
to the environment task, by specifying it for the main subprogram!)

  reply	other threads:[~2021-12-22 19:05 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-22  5:57 Ada.Numerics.Big_Numbers.Big_Integer has a limit of 300 digits? Michael Ferguson
2021-12-22  8:25 ` Mark Lorenzen
2021-12-22 11:14 ` AdaMagica
2021-12-22 11:32   ` AdaMagica
2021-12-22 16:04   ` AdaMagica
2021-12-22 17:37     ` Niklas Holsti
2021-12-22 20:34   ` Simon Wright
2021-12-22 17:01 ` Luke A. Guest
2021-12-22 17:27   ` Michael Ferguson
2021-12-22 17:43     ` Ben Bacarisse
2021-12-22 17:48     ` Niklas Holsti
2021-12-22 18:02       ` Michael Ferguson
2021-12-22 19:05         ` Niklas Holsti [this message]
2021-12-23  8:31           ` Luke A. Guest
2021-12-23  8:54             ` Dmitry A. Kazakov
2021-12-23 11:41           ` AdaMagica
2021-12-23 12:18             ` Niklas Holsti
2021-12-23 14:01               ` Ben Bacarisse
2021-12-22 19:26     ` Mark Lorenzen
2021-12-22 20:43       ` Niklas Holsti
2021-12-22 20:31     ` Paul Rubin
2021-12-22 20:39     ` Paul Rubin
2021-12-23 15:48 ` Jeffrey R.Carter
2021-12-24  9:09   ` AdaMagica
replies disabled

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