Int128 in .Net?

I need to do some great whole math. Are there any classes or structures that represent a 128-bit integer and implement all the usual operators?

By the way, I understand that a decimal number can be used to represent a 96-bit int.

+57
c # int128
Oct 22 '08 at 22:17
source share
12 answers

Here it is in System.Numerics . "The BigInteger type is an immutable type representing an arbitrarily large integer whose value in theory has no upper or lower bounds."

var i = System.Numerics.BigInteger.Parse("10000000000000000000000000000000"); 
+39
Oct 22 '08 at 22:39
source share

While BigInteger is the best solution for most applications, if you have critical numerical computations with performance, you can use the full implementations of Int128 and UInt128 in Dirichlet.Numerics . These types are useful if Int64 and UInt64 too small, but BigInteger too slow.

+16
Feb 01 '15 at 1:14
source share

No, there is nothing in .NET <= 3.5. I hope / expect BigInteger to return to .NET 4.0. (This was cut from .NET 3.5 .)

+12
Oct 22 '08 at 22:26
source share

If you don't mind referencing the J # library (vjslib.dll, which is included in VS by default), there is already an implementation of BigInteger in .NET.

 using java.math; public static void Main(){ BigInteger biggy = new BigInteger(....) } 
+2
Oct 23 '08 at 7:41
source share

BigInteger is now a standard part of C # and friends in .NET 4.0. See: Gunnar Papman, ASP.NET Blog . Please note that the CPU can usually work with regular integers much faster and in constant time, especially when using the usual mathematical operators (+, -, /, ...), because these operators are usually mapped directly to separate CPU instructions.

With BigInteger, even the simplest mathematical operations are much slower function calls for methods whose execution time depends on the size of the number. This is because BigInteger implements arithmetic of arbitrary precision, which adds significant but necessary overhead. The advantage is that BigIntegers are limited not by 64 or even 128 bits, but by the available system memory (or approximately 2 ^ 64 bits of accuracy, whichever comes first). Read here .

+2
Mar 21 2018-11-21T00:
source share

C # PCL library for calculations with large numbers such as Int128 and Int256. https://github.com/everbytes/BigMath

+1
Dec 15 '13 at 22:19
source share

The GUID is supported by a 128-bit integer in the .NET Framework; although this does not go with any of the typical integer type methods.

I wrote a handler for the GUID before treating it as a 128-bit integer, but that was for the company I worked for ~ 8 years ago. I no longer have access to the source code.

Therefore, if you need built-in support for a 128-bit integer and for some reason you do not want to rely on BigInteger, you could probably hack a GUID to accomplish your tasks.

+1
Feb 26 '18 at 18:32
source share

For those who Int128 on the legitimacy of Int128 / UInt128 in .NET, some work on UInt128 hardware embedded UInt128 and 128-bit mathematics in .NET was promoted by the MS Machine Learning initiative. There is a NuGet package here, which currently provides some facilities for regular 128-bit integer operations as long / ulong pairs, and may include hardware features in the future where available. Meanwhile, they provide a cross-platform library (CpuMathNative) that runs Div64 ("Divide the 128-bit value by lo and hi by den .") And Mul64 (" Mul64 two 64-bit values ​​to get a 128-bit result." ") , as well as MulDiv64 ("Multiply a and b and divide by den ", returning the quotient and putting the remainder in rem .), 128-bit v. 128-bit DivRound , Add , Sub , LessThan .

From this, you can easily create an Int128 and UInt128 and, possibly, pass it in hardware registers with careful use of the Vector128 implementation ( System.Runtime.Intrinsics ).

Although as a footnote, BigMath.PCL is still a good paste solution.

0
Jan 12 '19 at 23:06
source share

I believe Mono has a BigInteger implementation with which you must track the source.

-one
Oct 22 '08 at 22:28
source share

It implements the implementation of a large integer from .net.

http://msdn.microsoft.com/en-us/magazine/cc163696.aspx

-one
Oct 22 '08 at
source share

Here's the implementation of Int128 in .NET: https://int128.codeplex.com/

-one
Aug 26 '14 at 16:06
source share

Here, the BigInteger class is defined as part of IronPython that you could use.

-2
Oct 22 '08 at 23:47
source share



All Articles