[Issue 2289] Stack overflow on very large BigInt to string.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Aug 18 01:38:39 PDT 2008


http://d.puremagic.com/issues/show_bug.cgi?id=2289





------- Comment #3 from clugdbug at yahoo.com.au  2008-08-18 03:38 -------
(In reply to comment #0)
> import std.stdio, std.bigint;
> 
> void main() {
>     auto result = factorial(10_000);
>     writefln(stderr, "Calculated 10,000!");  //Works to this point.
>     auto resultString = result.toString;  //Generates stack overflow.
> }
> 
> BigInt factorial(uint N) {
>     BigInt result = 1;
>     for(uint i = 2; i <= N; i++) {
>         result *= i;
>     }
>     return result;
> }
> 
> Seems to happen at ~20k to 25k decimal digits.
> 
> A fairly minor bug, since it is very unlikely that too many people will run
> into it. (I only found it because I was testing the speed of std.bigint on very
> large numbers.) 

You'll find the speed of std.bigint is pretty awful. But don't worry, it will
improve _signficantly_. The version in Tango (work in progress) is 40X faster
for small numbers, rising to 100s of times faster as the number of digits
increases.


-- 



More information about the Digitalmars-d-bugs mailing list