我发现以下执行这些代码片段有点令人困惑:
BigInteger result = BigInteger.Pow(1000, 1000);
Run Code Online (Sandbox Code Playgroud)
这将编译没有错误但是这个不会:
BigInteger result = (BigInteger)Math.Pow(1000, 1000);
Run Code Online (Sandbox Code Playgroud)
执行BigInteger.Pow()和之间的区别是什么Math.Pow().在这两种情况下我们都是using System.Numerics.
第二个抛出OverflowException BigInteger不能表示无穷大.
1000^1000超出范围double,所以当你打电话给Math.Pow(1000,1000)它返回double.PositiveInfinity.
您无法分配double.PositiveInfinity给a BigInteger,因此错误.