IEEE 754 binary32 and binary64
Read the fields from the most significant bit. Classify the exponent code before calculating a value.
Field positions
| Field or parameter | binary32 | binary64 |
|---|---|---|
| C type on the lab target | float | double |
| Sign s | Bit 31 | Bit 63 |
| Stored exponent B | Bits 30 to 23 | Bits 62 to 52 |
| Fraction field F | Bits 22 to 0 | Bits 51 to 0 |
| Fraction width t | 23 | 52 |
| Exponent bias | 127 | 1023 |
| All-ones exponent code | 255 | 2047 |
| Precision for normal values | 24 bits | 53 bits |
| Actual normal exponent range | −126 to +127 | −1022 to +1023 |
Decode by exponent code
Read the fraction field as an unsigned integer F. The fraction is f = F / 2t. The full significand is 1 + f for normals and f for subnormals. For signed values, s = 0 is positive and s = 1 is negative.
| Exponent code B | Fraction | Class | Value |
|---|---|---|---|
| Zero | Zero | Signed zero | +0 or −0 |
| Zero | Nonzero | Subnormal | (−1)s × f × 21 − bias |
| Between zero and all ones | Any | Normal | (−1)s × (1 + f) × 2B − bias |
| All ones | Zero | Infinity | +∞ or −∞ |
| All ones | Nonzero | NaN | Not a number |
Binary32 landmarks
| Word | Meaning |
|---|---|
0x80000000 | −0 |
0x00000001 | Smallest positive subnormal, 2−149 |
0x00800000 | Smallest positive normal, 2−126 |
0x3f800000 | 1.0 |
0x7f7fffff | Largest finite positive value, (2 − 2−23) × 2127 |
0x7f800000 | +∞ |
0x7fc00000 | One quiet NaN encoding on x86 |
Within one normal exponent, adjacent fraction codes differ in magnitude by 2B − bias − t. On x86, the least significant byte comes first in memory.