我发现下面这些代码片段的执行有点让人困惑:
BigInteger result = BigInteger.Pow(1000, 1000);这将在编译过程中没有错误,但是这个错误不会:
BigInteger result = (BigInteger)Math.Pow(1000, 1000);BigInteger.Pow()和Math.Pow()的实现有什么区别?在这两种情况下,我们都是using System.Numerics。
第二个抛出OverflowException BigInteger不能表示无穷大。
发布于 2016-04-18 15:26:32
1000^1000超出了double的范围,所以当您调用Math.Pow(1000,1000)时,它返回double.PositiveInfinity。
不能将double.PositiveInfinity分配给BigInteger,因此出现了错误。
https://stackoverflow.com/questions/36698137
复制相似问题