I'm reviving this question, and making it more specific: Is there a .NET framework library that supports numbers with arbitrary digits of precision?
-
What you're looking for is an "arbitrary precision" decimal library, or maybe "bignum" type library. I haven't personally used any such libraries with .net, but maybe this question can help. http://stackoverflow.com/questions/621684/arbitrary-precision-decimals-in-c – Falaina Jul 23 '09 at 05:12
8 Answers
Can you wait for .NET 4.0? They're bringing BigInteger directly into the Framework.
On the other hand, if you can't wait, then the J# runtime includes built-in support for java.math.BigInteger and BigDecimal. This is redistributable just like the rest of the .NET Framework.

- 29,297
- 11
- 59
- 61
-
Here are some BigInteger options: http://stackoverflow.com/questions/25375/how-can-i-represent-a-very-large-integer-in-net/98678#98678 – Luke Quinane Oct 30 '09 at 01:07
-
1Unfortunately these are arbitrary size integers not arbitrary precision natural numbers. – RCIX Nov 02 '09 at 11:13
-
In this case look at these: J# library's java.math.BigDecimal – Vladislav Rastrusny Nov 03 '09 at 08:35
There are a few options here.
A good option is W3b.Sine, which is native C#/.NET, and supports arbitrary precision floating point values.
If you are only dealing with integer values, IntX provides support for arbitrary precision integer values. A potentially more mature option would be C# BigInt, but again, this will not support floating point operations.

- 554,122
- 78
- 1,158
- 1,373
You could try the old method of mantissa. Basically you could have an 64 bit integer for storing the number and then a 64 bit integer for storing the exponent (which could be negative). You could build your own object type and overload the arithmetic operators, so it will be treated as a single number. It will require some work, but I think it will be your best option.

- 3,064
- 3
- 26
- 27
-
Theoretically this would be easy to do; value types are, under the hood, all simple structs anyway. – Jon Limjap Jul 23 '09 at 05:22
-
Never heard of Decimal data type? This solution needs a huge amount of work to be done... – Davide Vosti Jul 23 '09 at 05:26
-
Did you see the questioner comment about "i am planning on storing something in the way of billions of digits"? – Freddy Jul 23 '09 at 05:30
-
You could start with this (which is the opposite of what you want, but it will give you an idea): http://stackoverflow.com/questions/389993/extracting-mantissa-and-exponent-from-double-in-c Here is some theory of the concept : http://www.cs.utah.edu/~zachary/isp/applets/FP/FP.html Before floating points units were available on hardware this was how it was done. – Freddy Jul 23 '09 at 05:41
-
@RCIX: http://msdn.microsoft.com/en-us/library/system.numerics.biginteger(VS.100).aspx – jasonh Nov 04 '09 at 02:33
GnuMpDotNet: http://www.emilstefanov.net/Projects/GnuMpDotNet/
If you need pure .NET consider looking into this: http://www.codeplex.com/IntX/

- 29,378
- 23
- 95
- 156
-
Both of these cover arbitrary size integer classes, but do they offer abitrary precision natural numbers? – RCIX Nov 02 '09 at 11:06
-
Natural number is a non-negative integer. So, they do. http://en.wikipedia.org/wiki/Natural_number – Vladislav Rastrusny Nov 02 '09 at 12:08
-
Perhaps surprisingly, the Bailey-Borwein-Plouffe formula gives an incremental procedure for computing the next binary or hexadecimal digit of pi without needing to store all the previous digits.

- 14,265
- 6
- 48
- 70
-
It was back when the question asked how to calculate arbitrarily many digits of pi in C#, the questioner changed it a few months later to something "more specific" but in fact only tangentially related. – Doug McClean Feb 24 '15 at 19:36
You can use decimal type which gives you 28-29 significant digits

- 69,610
- 20
- 126
- 152
-
that helps a little... but i am planning on storing something in the way of billions of digits. I was thinking something along the lines of a string solution but have no clue where to start. – RCIX Jul 23 '09 at 05:06