2

I'm reviving this question, and making it more specific: Is there a .NET framework library that supports numbers with arbitrary digits of precision?

JAL
  • 41,701
  • 23
  • 172
  • 300
RCIX
  • 38,647
  • 50
  • 150
  • 207
  • 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 Answers8

6

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.

jasonh
  • 29,297
  • 11
  • 59
  • 61
5

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.

Reed Copsey
  • 554,122
  • 78
  • 1,158
  • 1,373
3

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.

Freddy
  • 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
3

GnuMpDotNet: http://www.emilstefanov.net/Projects/GnuMpDotNet/

If you need pure .NET consider looking into this: http://www.codeplex.com/IntX/

Vladislav Rastrusny
  • 29,378
  • 23
  • 95
  • 156
2

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.

Doug McClean
  • 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
2

If you want a really fast library then try:

http://www.emilstefanov.net/Projects/GnuMpDotNet/

Emil
  • 21
  • 1
1

You can use decimal type which gives you 28-29 significant digits

RaYell
  • 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
1

Here is a good article on how to represent infinite digits.

http://dobbscodetalk.com/index.php?option=com_myblog&show=Basic-Arithmetic-with-Infinite-Integers.html&Itemid=29

good luck