views:

870

answers:

5

I want to be able to process arbitrarily large numbers in C#.
I can live with just integers.

Are there established algorithms for this kind of thing?
Or is there a good 3rd-party library?

I might consider changing language if there really is no good way to do it in C#.

Thanks for any help / suggestions.

+7  A: 

search is your friend

http://stackoverflow.com/questions/25375/how-can-i-represent-a-very-large-integer-in-net

http://stackoverflow.com/questions/176775/big-integers-in-c

Tim
doh! I'm an idiot for not finding these.
AJ
actually, the search terms were not what I expected... there was a lot of junk in the initial terms I used.
Tim
+3  A: 

You might want to check the Big Num kind of libraries. In C# the most popular ones are: IntX and W3b.Sine, plus, they are both Open Source.

Manuel Ferreria
Thanks for the links, havent seen those 2 before :) Maybe they will be faster than the rubbish in the DLR!
leppie
+1  A: 

If you just need very large numbers, you could use long (64-bit), or even decimal (128-bit floating point).

If you need values larger than 9223372036854775807 (long) or 79228162514264337593543950335 (decimal), then you need to ignore this answer.

David Kemp
+3  A: 

Someone has done a BigInteger class in C# at codeproject C# BigInteger Class. Worth checking out.

And a sample of the general algorithm can be found at : Re: Hi-prec math for visual studio c#? (It's the post at the bottom of the page with the code snippet)

GeneQ
+2  A: 

As people have mentioned, there are various 3rd-party implementations of a BigInteger class. Also, C# 4.0 will be getting a native BigInteger class in the CLR.

Scott Dorman