关于bignum:如何在.NET中表示一个非常大的整数?

关于bignum:如何在.NET中表示一个非常大的整数?

How can I represent a very large integer in .NET?

.NET是否带有能够表示极大整数(例如100阶乘)的类? 如果没有,那么有哪些好的第三方库可以完成此任务?


.NET 4具有BigInteger类

Represents an arbitrarily large signed integer.

The BigInteger type is an immutable type that represents an arbitrarily large integer whose value in theory has no upper or lower bounds. This type differs from the other integral types in the .NET Framework, which have a range indicated by their MinValue and MaxValue properties.


.NET具有BigInteger类,但是很遗憾,它是内部的。但是,几个地方都有自己的地方。您可以从IronPython或CodeProject或Visual J#中获取一个实现。我不得不说,我自己还没有尝试过这些,所以我不知道哪个是最好的。

http://www.codeplex.com/IronPython
http://www.codeproject.com/KB/cs/biginteger.aspx
http://msdn.microsoft.com/zh-CN/magazine/cc163696.aspx


Microsoft.FSharp.Math.Types.BigInt

它可以代表任何整数。


这是框架4.0中大整数文档的链接

http://msdn.microsoft.com/zh-CN/library/system.numerics.biginteger(VS.100).aspx


Mono已经有一个公共的BigInteger实现:

http://www.go-mono.com/docs/index.aspx?link=T:Mono.Math.BigInteger

您只需获取Mono.Security程序集即可使用它;由于它具有Mono类库,因此也应获得MIT许可。


推荐阅读