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!
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.
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.