Obscure Isssue #1

H. S. Teoh hsteoh at qfbox.info
Fri Aug 5 15:07:18 UTC 2022


On Fri, Aug 05, 2022 at 02:23:15PM +0000, Ruby The Roobster via Digitalmars-d-learn wrote:
> On Friday, 5 August 2022 at 14:11:09 UTC, H. S. Teoh wrote:
> > On Fri, Aug 05, 2022 at 01:56:40PM +0000, Ruby The Roobster via
> > Digitalmars-d-learn wrote: [...]
> > > public import dutils.math.core;
> > 
> > Is the imported module available anywhere?  I'm trying to run your
> > code sample to determine what's going on, but it's not compiling
> > because you didn't post the code to dutils.math.core.
[...]
> You can cut that and the Number class out.  They're not relevant to
> the bug.  Sorry for not mentioning that.

It's actually not a bug.  Running the code in the debugger shows that
it's getting stuck (well not really stuck, just taking a long time)
inside std.bigint.BigInt.pow, which is being called with the value 10
and an exponent of 18030.

In other words, you're trying to construct a BigInt with a value of
10^18030 (a number with 18030 digits) and wondering why the computer is
taking forever to compute the value. :-D

Keep in mind that BigInt stores numbers in binary format, so this isn't
just a matter of bumping an exponent field like in a base-10 floating
point format: it actually has to compute the exponentiation by
multiplying each increasingly-large intermediate number by 10, for a
total of 18030 times. The multiplication itself isn't the problem, but
the amount of storage it takes to store a number with 18030 digits and
the amount of time it takes to traverse this storage to manipulate its
value.


T

-- 
Give a man a fish, and he eats once. Teach a man to fish, and he will sit forever.


More information about the Digitalmars-d-learn mailing list