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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Aug 17 11:56:05 PDT 2008


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

           Summary: Stack overflow on very large BigInt to string.
           Product: D
           Version: 2.018
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: minor
          Priority: P4
         Component: Phobos
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: dsimcha at yahoo.com


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.)  If this can't be fixed easily, maybe just a better error
message such as "Error:  Too many digits." would be good enough.


-- 



More information about the Digitalmars-d-bugs mailing list