I need a c# number something that can handle very large numbers but also fraction support, I looked at System.Numerics.BigInteger coming in .NET 4.0 but I can't get it to work with fractions.
something i = 2;
something j = 5;
something k = i/j; //should be 0.4
when i tried
BigInteger i = 2;
BigInteger j = 5;
double d = (double)(i/j); //d is 0.0
Does anybody know such a library?
F# PowerPack contains a numeric type BigRational
. It is implemented in F# and designed for F#, but the type should be perfectly usable from C# as well (including overloaded operators and stuff like that). PowerPack is an additional library with extra F# features, so it isn't a part of the .NET framework, but it's a supported product from Microsoft.
The BigRational
type supports all basic operators (+, /, -, *, >, <, >=, <=, ==, !=
) and I believe that it automatically keeps a normal form of the number. If you represented the number as two BigInteger
values, you'd have to implement comparison such that 1/2 equals 2/4.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With