Mahmoud
Mahmoud

Reputation: 197

Compute a very big power using C++

I have a very big power

e.x. 5^4912

double x, y, z;

I used z = pow( x, y ) function, but it gives me this result: [ 1.#INF ]

then, I tried to use a for loop that loops in 4912, but it gives me number like

-957893823 

which seems rubbish

How can I solve a problem like that?

Upvotes: 0

Views: 3695

Answers (2)

Mohit Kumra
Mohit Kumra

Reputation: 11

In order to get large factorials and calculate large values use BigIntegers.
BigInteger in c++


Refer this link :http://www.cplusplus.com/forum/general/108176/

Upvotes: 1

codeling
codeling

Reputation: 11369

The built-in data types (int, long and even double) can't hold the result of that calculation; so you can't use these.

Depending on the exact use case, I would recommend using a fitting library, e.g.:

Upvotes: 2

Related Questions