# question about pow()

• 11-04-2008
l2u
Hello

Why will the following code output integer c as 0 (null)?

Code:

```unsigned int c = pow( (double)2 , (double)1000); std::cout << c << "\n";```
What would be the proper way of calculating 2^1000 in c++?

Thanks a lot!
• 11-04-2008
Waterbottle
An unsigned int is unable to store values larger than 2^32.

I believe a double would be able to store it. Otherwise you would need a to use a bignum library.
• 11-04-2008
cyberfish
Even if a double can store it, it won't be with infinite precision. You will only get a few significant figures.

If you want the answer with infinite precision, you will have to use a bignum library.
• 11-05-2008
matsp
Quote:

Originally Posted by Waterbottle
An unsigned int is unable to store values larger than 2^32.

I believe a double would be able to store it. Otherwise you would need a to use a bignum library.

Actually: (2^32)-1 is the largest you can fit in a 32-bit integer.

A double should be able to store 1.07E301, which is roughly the value of 2^1000.

--
Mats
• 11-05-2008
Elysia
Oh and just poking, but in C++, it is really in our best to use the C++ variants of the C functions, std::pow.
There should be one, no?