This is obviously to big for double. How it's working?
21000 is within the range of numbers that can be represented by a double. So this number obviously is not too big for a double.
I suspect that what you mean by "too big" is that the number of digits printed is much greater than the 16 or so digits that can be stored in a double. There's nothing wrong with asking a computer to print more than 16 decimal digits. What's wrong is assuming that those extra digits have any meaning.
In this particular case, the printed number is exactly correct. That's because the computer treats pow(2,some_int)
specially. Powers of 2 can be represented exactly in a double. The algorithm used to compute the decimal representation of an exact integral value will give the exactly correct decimal representation.
Anything else, all bets are off. Change your program so it prints 3646 for example:
#include <math.h>
#include <stdio.h>
int main(){
double somenumber = pow(3, 646);
printf("%lf
", somenumber);
return 0;
}
It will still print a big long number, but only the first 16 or so digits will be correct.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…