tags:

views:

1766

answers:

6
+4  Q: 

Int128 in .Net?

I need to do some large integer math. Are there any classes or structs out there that represent a 128-bit integer and implement all of the usual operators?

BTW, I realize that decimal can be used to represent a 96-bit int.

+3  A: 

No, there's nothing in .NET <= 3.5. I'm hoping/expecting that BigInteger will make its return in .NET 4.0. (It was cut from .NET 3.5.)

Jon Skeet
Well hopefully they will rewrite that junk! :)
leppie
A: 

I believe Mono has a BigInteger implementation that you should be able to track down the source for.

Craig
+1  A: 

Here's an implementation of big integer from .net matters.

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

Joe Basirico
+6  A: 

You might be able to use Microsoft.FSharp.Math.BigInt. As Jon points out, with any luck we may see an authorized version in .NET 4.0.

Update: It's here in System.Numerics. "The BigInteger type is an immutable type that represents an arbitrarily large integer whose value in theory has no upper or lower bounds."

var i = System.Numerics.BigInteger.Parse("10000000000000000000000000000000");
Larsenal
A: 

There's a BigInteger class defined as part of IronPython that you could use.

Curt Hagenlocher
+2  A: 

If you don't mind making reference to the J# library (vjslib.dll included with VS by default) there is already and implementation of BigInteger in .NET

using java.math;

public static void Main(){
    BigInteger biggy = new BigInteger(....)

}
sbeskur
Ha. Go figure. Excellent find!
lc