为什么 BigInteger 不可能进行 Factorial 1000?

Why is Factorial 1000 impossible with BigInteger?

所以当你谷歌时,它说 C# 中的 BigInteger 是无限的,但是 1000 的阶乘是未定义的。我做了这个简单的递归方法,它 returns 非常大。

static BigInteger faculty(int n) {

        if(n == 2)
            return 2;
        return n*faculty(n-1);
    }

所以这可能是溢出,但这是否意味着 BigIntegers 不是无限的?

不是(不可能)。以下代码在这里工作得很好(在 .NET Core 3.1 和 .NET Framework 4.7.2 上测试):

var x = faculty(1000);
var s = x.ToString();
Console.WriteLine(s.Length); // 2568 (digits)
Console.WriteLine(s); // 402387260...000000 (lots of digits)