Indeed, a float is only 32 bits (4 bytes) while a long is 64 bits (8 bytes).
But float is ofcourse a different kind of number - a floating point number instead of an integer. The limits (minimum and maximum values that it can hold) are different. The range of float is even larger than that of float, even though it has less bits!
The trick is that float is less precise - it has only about 6 decimal digits of precision. So you cannot store any number that fits into a long with the same precision into a float.
Try this, for example:
The output is:
You see that the float cannot exactly contain the number as the long, there is a rounding error in the last digits. [ August 29, 2006: Message edited by: Jesper Young ]
The assignment for float and double values is some what different from just copy the bits. The same bit pattern in long 64 bits area will be treated differently when it is assigned to double for float.