Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you do maths (or math) with numbers bigger than MaxValue in C#? [duplicate]

Tags:

c#

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.

like image 380
AJ. Avatar asked Nov 04 '08 14:11

AJ.


People also ask

Is there a math Max in C?

Description: The max() function returns the greater of two values. The max() function is for C programs only. For C++ programs, use the __max() macro.

What's bigger than int in C?

Longer integers: long The long data type stores integers like int , but gives a wider range of values at the cost of taking more memory. Long stores at least 32 bits, giving it a range of -2,147,483,648 to 2,147,483,647. Alternatively, use unsigned long for a range of 0 to 4,294,967,295.

What is the maximum value of numbers?

This number is the data value that is greater than or equal to all other values in our set of data. If we were to order all of our data in ascending order, then the maximum would be the last number listed. The maximum is a unique number for a given set of data.


3 Answers

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.

like image 105
Manuel Ferreria Avatar answered Sep 30 '22 07:09

Manuel Ferreria


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)

like image 43
GeneQ Avatar answered Sep 30 '22 07:09

GeneQ


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.

like image 38
Scott Dorman Avatar answered Sep 30 '22 08:09

Scott Dorman