views:

417

answers:

9

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

+1  A: 

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

RaYell
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
+3  A: 

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
Theoretically this would be easy to do; value types are, under the hood, all simple structs anyway.
Jon Limjap
Never heard of Decimal data type? This solution needs a huge amount of work to be done...
Davide Vosti
Did you see the questioner comment about "i am planning on storing something in the way of billions of digits"?
Freddy
This does sound like the best idea but i'm not sure where to start. Hmm...
RCIX
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-cHere is some theory of the concept : http://www.cs.utah.edu/~zachary/isp/applets/FP/FP.htmlBefore floating points units were available on hardware this was how it was done.
Freddy
@RCIX: http://msdn.microsoft.com/en-us/library/system.numerics.biginteger(VS.100).aspx
jasonh
+1  A: 

Check this link http://jsfromhell.com/classes/bignumber its a javascript code but you can easily convert it to your own in any language or in C#.

S M Kamran
+1  A: 

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

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

good luck

infinitesimal
+1  A: 

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
+4  A: 

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
Here are some BigInteger options: http://stackoverflow.com/questions/25375/how-can-i-represent-a-very-large-integer-in-net/98678#98678
Luke Quinane
Unfortunately these are arbitrary size integers not arbitrary precision natural numbers.
RCIX
In this case look at these: J# library's java.math.BigDecimal
FractalizeR
+1  A: 

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

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

FractalizeR
I would also vouch for IntX. Very good performance.
leppie
Both of these cover arbitrary size integer classes, but do they offer abitrary precision natural numbers?
RCIX
Natural number is a non-negative integer. So, they do.http://en.wikipedia.org/wiki/Natural_number
FractalizeR
Ok, let me rephrase that. an arbitrary precision *decimal* number?
RCIX
+2  A: 

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
A: 

If you want a really fast library then try:

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

Emil