0

Is there any library to handle numbers bigger than that a BigInteger in .net can handle? Using BigInteger I could calculate the fibonacci series up to 3226th term. How to calculate more terms? Is there a way to join two BigInteger when an overflow occurs? Looking for your help.

4

2 回答 2

2

使用BigInteger处理 .Net 中的未知大数,没有其他方法。如果它溢出了,这个数字简直太大了,无法处理,看不到:

因为 BigInteger 类型是不可变的(请参阅 Mutability 和 BigInteger 结构)并且因为它没有上限或下限,所以对于导致 BigInteger 值增长过大的任何操作都可能引发 OutOfMemoryException。

于 2013-08-04T13:20:31.417 回答
1

我认为问题是你的,而不是BigInteger

BigInteger prev2 = 1;
BigInteger prev1 = 1;

int i = 3;

while (true)
{
    BigInteger fi = prev2 + prev1;
    Console.WriteLine("{0}th: {1}", i, fi);
    prev2 = prev1;
    prev1 = fi;
    i++;
}

它毫无问题地到达第 300000 个。

于 2013-08-04T14:22:30.233 回答