Originally posted by James Du:
Hi,
We know that type long has 64bits, so the the amount of the distinct numbers it can hold is 2 to the power of 64.
My puzzle is: since type double has the same number of bits, why it could hold the number greater than long both in precision and in magnitude? How many numbers could it distinguish?
Hi James,
You can find the answer in JLS or IEEE 754 standard. But here is a short answer:
The finite nonzero values of any floating-point value set can all be expressed in the form s * m * Math.pow(2,e-N-1) where
s is +1 or -1, m is a positive integer less than Math.pow(2,N), and
e,
the exponential component, is an integer between
Emin = -(Math.pow(2,K-1) - 2) and
Emax = (Math.pow(2,K-1) - 1), inclusive.
For float N = 24 and K = 8. Emin = -126, Emax = 127
For double N = 53 and K = 11. Emin = -1022. Emax = 1023.
So as you can see, the exponential component for a double is quite large compared to a long.
- Lam -
[This message has been edited by Lam Thai (edited May 16, 2001).]