Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a 128 or 256 bit double class in .net?

I have an application that I want to be able to use large numbers and very precise numbers. For this, I needed a precision interpretation and IntX only works for integers.

Is there a class in .net framework or even third party(preferably free) that would do this?

Is there another way to do this?

like image 589
akshaykarthik Avatar asked Jun 03 '10 16:06

akshaykarthik


3 Answers

Maybe the Decimal type would work for you?

like image 70
Tim Pietzcker Avatar answered Oct 16 '22 01:10

Tim Pietzcker


You can use the freely available, arbitrary precision, BigDecimal from java.math, which is part of the J# redistributable package from Microsoft and is a managed .NET library.

Place a reference to vjslib in your project and you can something like this:

using java.math;

public void main() 
{
    BigDecimal big = new BigDecimal("1234567890123456789011223344556677889900.0000009876543210000987654321");
    big.add(new BigDecimal(1.0));
    Debug.Print(big);
}

Will print the following to the debug console:

1234567890123456789011223344556677889901.0000009876543210000987654321

Note that, as already mentioned, .NET 2010 contains a BigInteger class which, as a matter of fact, was already available in earlier versions, but only as internal class (i.e., you'd need some reflection to get it to work).

like image 6
Abel Avatar answered Oct 15 '22 23:10

Abel


The F# library has some really big number types as well if you're okay with using that...

like image 4
Justin Avatar answered Oct 16 '22 01:10

Justin