Int128 in .Net?

非 Y 不嫁゛ 提交于 2019-11-27 20:21:08
Larsenal

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");

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

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

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

}

BigInteger is now a standard part of C# and friends in .NET 4.0. See:Gunnar Peipman's ASP.NET blog. Note that the CPU can generally work with ordinary integers much more quickly and in constant time, especially when using the usual math operators (+, -, /, ...) because these operators typically map directly to single CPU instructions.

With BigInteger, even the most basic math operations are much slower function calls to methods whose runtime varies with the size of the number. This is because BigInteger implements arbitrary precision arithmetic, which adds considerable but necessary overhead. The benefit is that BigIntegers are not limited to 64 or even 128 bits, but by available system memory (or about 2^64 bits of precision, whichever comes first). Read here.

GUID is backed by a 128 bit integer in .NET framework; though it doesn't come with any of the typical integer type methods.

I've written a handler for GUID before to treat it as a 128 bit integer, but this was for a company I worked for ~8 years ago. I no longer have access to the source code.

So if you need native support for a 128 bit integer, and don't want to rely on BigInteger for whatever reason, you could probably hack GUID to server your purposes.

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

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

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

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

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!