6

Possible Duplicate:
Big integers in C#

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.

Community
  • 1
  • 1
AJ.
  • 13,461
  • 19
  • 51
  • 63

4 Answers4

3

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
  • 1,216
  • 1
  • 13
  • 23
  • Thanks for the links, havent seen those 2 before :) Maybe they will be faster than the rubbish in the DLR! – leppie Nov 04 '08 at 14:31
3

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
  • 7,485
  • 6
  • 37
  • 53
2

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
  • 42,236
  • 12
  • 79
  • 110
1

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.

kͩeͣmͮpͥ ͩ
  • 7,783
  • 26
  • 40