D
David Mathog
I just observed that
double var;
double N; /* an integer */
var=pow(2.0,N)
fprintf(stdout,"%.*lf\n",0,var);
Returns what appears to be the right value for everything up to
N=1023. At 1024 it returns inf.
Example:
2^256
115792089237316195423570985008687907853269984665640564039457584007913129639936
(The highest value I could find in a quick web search, to verify that
the long string was correct.)
Verified that the double wasn't somehow miraculously carrying that
much precision (linking in an arbitrary precision library or something
along those lines), by repeating the calculation with
var=pow(2.0,N)-100
As expected, it returned the same value for large N as did the
original. So no miraculous precision in general.
I assume that fprintf is somehow deriving all of these (correct)
digits from the exponent when it goes to print the double. Other than
the integer powers of 2, are there any other "extended precision"
values that can be found this way? Is this standard behavior, or just
something the gcc compiler does?
Thanks,
David Mathog
double var;
double N; /* an integer */
var=pow(2.0,N)
fprintf(stdout,"%.*lf\n",0,var);
Returns what appears to be the right value for everything up to
N=1023. At 1024 it returns inf.
Example:
2^256
115792089237316195423570985008687907853269984665640564039457584007913129639936
(The highest value I could find in a quick web search, to verify that
the long string was correct.)
Verified that the double wasn't somehow miraculously carrying that
much precision (linking in an arbitrary precision library or something
along those lines), by repeating the calculation with
var=pow(2.0,N)-100
As expected, it returned the same value for large N as did the
original. So no miraculous precision in general.
I assume that fprintf is somehow deriving all of these (correct)
digits from the exponent when it goes to print the double. Other than
the integer powers of 2, are there any other "extended precision"
values that can be found this way? Is this standard behavior, or just
something the gcc compiler does?
Thanks,
David Mathog