[Nickle] BigInteger bug

Michel Salim michel.salim at gmail.com
Mon Feb 27 19:47:19 PST 2006


So I do realize that the code from CVS HEAD is canonical, but it's
currently in a non-building state.. I thus can't verify whether this
works in recent CVS builds or not.

As seen from the code below, it seems that the conversion from integer
to big integer is not done at the right spot, and given two
sufficiently large numbers the sum is negative.

> print fib
int fib (int n)
{
    return fibh (n, 1, 1);
}
> print fibh
int fibh (int n, int a, int b)
{
    if (0 == n)
        return a;
    else
        return fibh (n - 1, b, a + b);
}
> fib(42)
433494437
> fib(43)
701408733
> 4334944370
4334944370
> 4334944370 + 701408733
5036353103
> 433494437 + 701408733
-1012580478


--
Michel Salim
http://www.cs.indiana.edu/~msalim
http://the-dubois-papers.blogspot.com/


More information about the Nickle mailing list