如何在.NET中表示一个非常大的整数?
时间:2020-03-05 18:42:40 来源:igfitidea点击:
.NET是否带有能够表示极大整数(例如100阶乘)的类?如果不是,那么有哪些好的第三方库可以完成此任务?
解决方案
回答
.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
它可以代表任何整数。
回答
.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.
回答
Mono已经有一个公共的BigInteger实现:
http://www.go-mono.com/docs/index.aspx?link=T:Mono.Math.BigInteger
我们只需获取Mono.Security程序集即可使用它;由于它具有Mono类库,因此也应该获得MIT的许可。
回答
这是框架4.0中大整数文档的链接
http://msdn.microsoft.com/zh-cn/library/system.numerics.biginteger(VS.100).aspx