1 MAX_FLOAT. IEEE 754 2 ( ).
IEE-754 1 , 8 23 .
. - 1/2, 1/4, 1/8...
1 1.999... . (1) 1
2 3.999... . (2,3) 2 .
3 , -.
. 2 3
.
4 7.999... . (4, 6, 7) 4 ,
2 . , .
8 15.999... . 8 (8,9,10,11,12,13,14,15)
3 . , .
Hopefully you will see a picture when the exponent increases, the number of possible integers doubles. Therefore, ignore the n bits of the highest mantissa and check if the least significant bits are set. If they are then this number is not an integer.
These tables indicate the value of the constant 0x40 plus the next most significant bit, and that only integer bits of the high order mantissa are given for integers
Float Hex
4 0x40800000
5 0x40a00000
6 0x40c00000
7 0x40e00000
To convert float to UInt32
float x = 7.0;
UInt32 * px = (UInt32*)&x;
UInt32 i = *px;
source
share