简体   繁体   English

C#内存类型大于ulong

[英]C# memory type bigger than ulong

I need to do huge power calculations (think 2 ^ 1,000,000) in C#, and a ulong is nowhere near sufficient. 我需要在C#中进行大功率计算(想想2 ^ 1,000,000),而ulong远远不够。 There's probably not anything bigger implemented in the .NET, but is there some 3rd party thing, or even something I can make that will work? 在.NET中可能没有更大的实现,但是有一些第三方的东西,甚至是我可以制作的东西吗?

If you are using the .NET Framework 4.0, you can use BigInteger . 如果您使用的是.NET Framework 4.0,则可以使用BigInteger Just add a reference to the System.Numerics assembly. 只需添加对System.Numerics程序集的引用。

There are plenty of other implementations as well if the .NET Framework 4.0 isn't available to you, like this one on CodeProject. 如果您无法使用.NET Framework 4.0,那么还有很多其他实现,例如CodeProject上的这个

您可以使用.Net 4.0中的System.Numerics.BigInteger

The term for what you appear to be looking for is "arbitrary precision arithmetic" and, in the case of 2^1,000,000, an arbitrary precision integer. 您看起来正在寻找的术语是“任意精度算术”,在2 ^ 1,000,000的情况下,是任意精度整数。

System.Numeric.BigIntegers in .NET 4 will likely work fine. .NET 4中的System.Numeric.BigIntegers可能正常工作。

If you need to use an earlier version of .NET or any other language, or need more features or performance, the GMP library is the usual stop for uncommon math. 如果您需要使用早期版本的.NET或任何其他语言,或者需要更多功能或性能, GMP库是常见数学运算的常用句点。 GMP is written in C and is available through wrappers for just about any other language. GMP是用C语言编写的,可以通过几乎任何其他语言的包装器获得。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM