Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there support for arbitrary precision arithmetic in C#?

Does C# support arbitrary precision arithmetic (I think this is also called bignums)?

If it doesn't, which libraries do support it?

like image 865
Oztaco Avatar asked Mar 15 '12 21:03

Oztaco


3 Answers

There is a BigInteger structure that supports arbitrary-size integers.

http://msdn.microsoft.com/en-us/library/system.numerics.biginteger.aspx

Nothing for floating-point though.

like image 130
Kendall Frey Avatar answered Sep 20 '22 07:09

Kendall Frey


You've already found the big integer; if you need big rational numbers (that is, fractions where the numerator and denominator are big integers) you can use the Rational class from the Solver library:

http://msdn.microsoft.com/en-us/library/microsoft.solverfoundation.common.rational(v=vs.93).aspx

like image 20
Eric Lippert Avatar answered Sep 21 '22 07:09

Eric Lippert


F# has a BigNum type at Microsoft.FSharp.Math.BigNum, you should be able to use it from C# as well.

This type exists in the F# Powerpack . Download it and reference the appropriate DLL (I suppose it's FSharp.Powerpack.Dll, but you'll need a little trial and error).

like image 32
zmbq Avatar answered Sep 19 '22 07:09

zmbq