Is there support for arbitrary precision arithmetic in C#?
Asked Answered
G

3

5

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

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

Gullet answered 15/3, 2012 at 21:14 Comment(1)
https://mcmap.net/q/303929/-big-integers-in-cCinchona
G
6

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.

Garrote answered 15/3, 2012 at 21:42 Comment(1)
BigInt doesn't support arbitrary precision, it supports arbitrarily large integers. It only supports integers. If you want arbitrary precision, you need the BigNum class.Bischoff
I
6

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

Irishirishism answered 15/3, 2012 at 22:54 Comment(0)
B
3

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

Bischoff answered 15/3, 2012 at 21:16 Comment(4)
fsharp sidnt show up in intellisense so i put csharp instead and it doesnt have Microsoft.CSharp.Math.BigNum, and as i said Microsoft.FSharp... doesnt exist eitherGullet
ah thanks, i added the reference and now i can use Microsoft.FSharp exists, but not Mi..ft.FSharp.Math.BigNum?Gullet
That just goes to show you I shouldn't be handing out F# advice, having only started to use it today... It's part of the F# Powerpack. Hold on, I'll edit again.Bischoff
thanks but i just found it under System.Numerics while looking through intellisenseGullet

© 2022 - 2024 — McMap. All rights reserved.