We all know that the floating point type occupies 4 bytes of space in the memory, while the long type occupies 8 bytes of space. But why is the maximum value of the four-byte Float Type greater than that of the long type?
We all know that the float type ranges from 3.403e38 ~ 3.403e38. The range of the Long type is-2 ^ 63 ~ 2 ^ 63-1 (about 9*10 ^ 18 ).
I used to simply remember that even when I was done, I did not think about why it was like this.
The following is my understanding:
Long Integer, which occupies 8 bytes in 64-bit memory. It indicates that the value has the power of 2 and is evenly divided between positive and negative values, the value range is 63 power of negative 2 to 63 power-1 of positive 2.
Float occupies 4 bytes in the memory, which is 32 characters in total, but the floating point is in the memory as follows:
V = (-1) ^ s * m * 2 ^ e
The 32-bit floating point does not represent the size directly, but is allocated according to certain standards.
The value is 1st BITs, which is the symbol bit (s.
The next 8 digits are the index fields, that is, E.
The value range of the remaining 23 digits, a small number field, that is, M and M is [1, 2) or [0, 1 ).
That is to say, the binary value of a floating point in the memory is not directly converted to a decimal value, but calculated according to the above formula. Through this formula, although only four bytes are used, however, floating point numbers are larger than the maximum values of long integers.
This is why the long type is converted to the float type during data conversion!