views:

165

answers:

3
+1  Q: 

Really big number

First of all apologies if there is already a topic like this but I have not found... I need to know how to handle a really big number such as the result of 789^2346:

#include <iostream>
#include <cmath>
using namespace std;
int main () {
    cout << pow(789,2346) << endl;
}
+4  A: 

You need a "big number" library. A popular choice is GNU's Multiple Precision Arithmetic Library, which has a C interface. I's also been around for a while. Another one, for C++, is Big Integer Library.

I'm sure there is a list of bignum libraries on SO somewhere, but I cannot find it. There is a tag you could stroll through.

GMan
+6  A: 

You could try the GNU MP Bignum Library or ttmath. This link point to some samples. It is very easy to use.

Bruno Reis
There is also the Big Number library in OpenSSL crypto section: http://www.openssl.org/docs/crypto/bn.html
Thomas Matthews
A: 

You can consider NTL (Number Theory Library) for C++ - http://www.shoup.net/ntl/ . It's very easy to use.

If you can relax C++ requirement, Perl and Python support big integers natively. PHP supports via bcmath or gmp extensions.

Viet