Hello
Why will the following code output integer c as 0 (null)?
What would be the proper way of calculating 2^1000 in c++?Code:unsigned int c = pow( (double)2 , (double)1000);
std::cout << c << "\n";
Thanks a lot!
Printable View
Hello
Why will the following code output integer c as 0 (null)?
What would be the proper way of calculating 2^1000 in c++?Code:unsigned int c = pow( (double)2 , (double)1000);
std::cout << c << "\n";
Thanks a lot!
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.
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.
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?