简体   繁体   中英

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. 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?

If you are using the .NET Framework 4.0, you can use BigInteger . Just add a reference to the System.Numerics assembly.

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 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.

System.Numeric.BigIntegers in .NET 4 will likely work fine.

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. GMP is written in C and is available through wrappers for just about any other language.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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