From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.6 X-Received: by 2002:ac8:5a84:: with SMTP id c4mr3015814qtc.565.1640196161902; Wed, 22 Dec 2021 10:02:41 -0800 (PST) X-Received: by 2002:a25:c60d:: with SMTP id k13mr5955909ybf.615.1640196161666; Wed, 22 Dec 2021 10:02:41 -0800 (PST) Path: eternal-september.org!reader02.eternal-september.org!news.misty.com!border2.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: Wed, 22 Dec 2021 10:02:41 -0800 (PST) In-Reply-To: Injection-Info: google-groups.googlegroups.com; posting-host=98.175.171.200; posting-account=_mt0NQoAAABIfwNsuLpi-_70qS5Wcu3m NNTP-Posting-Host: 98.175.171.200 References: <304dcae2-8b20-43ff-8769-32fa06d4dc10n@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <41879a68-95cf-41e7-a582-4358a39f9d47n@googlegroups.com> Subject: Re: Ada.Numerics.Big_Numbers.Big_Integer has a limit of 300 digits? From: Michael Ferguson Injection-Date: Wed, 22 Dec 2021 18:02:41 +0000 Content-Type: text/plain; charset="UTF-8" Xref: reader02.eternal-september.org comp.lang.ada:63244 List-Id: 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. > >>> > >>> It is repeatedly described as an "arbitrary precision library" > >>> that has user defined implementation. > Surely not "user defined"? Possibly "implementation defined". > >>> I was under the impression that this library would be able to > >>> infinitely calculate numbers of any length, > I have the same impression (up to Storage_Error, of course). > >> but there is clearly a default limit of 300 digits. > >> What are you doing that requires that number of digits? > > > > I am working on ProjectEuler.net problem number 48. > > > > The questions asks you to sum the numbers n^n for (2 <= n <= 1000) > > and determine what the last ten digits of this number are. > > > > Obviously, this is quite a trivial problem when using any arbitrary > > precision library. > > > > I had incorrectly determined that 700^700 had 300 digits, in fact > > 700^700 = 3.7E1991. > > > > However, my code strictly breaks when the loop range is set to 683, > > which 683^683 = 8.12E1935. > How does it break? Some exception, or something else? > > Mark Lorenzen suggested in an earlier post that the limit might be in > the Big_Integer'Image function. The package > Ada.Numerics.Big_Numbers.Big_Integers has some other output operations > that you could try: > > function To_String (Arg : Valid_Big_Integer; ...) return String; > > procedure Put_Image (Buffer : ... ; Arg: in Valid_Big_Integer); > > Of course those might be internally linked to the 'Image function and > have the same possible limitation. Not 100% sure what modular types are 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" 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.