IEEE 754 Floating Point
Slides 57–66 — the biggest block on your exam. The whole topic is one formula plus one packing procedure. Get those two right and every question falls out.
1. Why we need it
Integers can't express:
- numbers with fractions —
3.1416 - very small numbers —
0.00000000023 - very large numbers —
So we borrow scientific notation, in base 2:
- More bits for the significand (a.k.a. mantissa) ⇒ more accuracy.
- More bits for the exponent ⇒ more range.
2. Normalized form
Slide the binary point until one 1 sits to its left; each place you slide it adjusts the exponent.
| Binary | Normalized | Why |
|---|---|---|
| 0.001 | point moved 3 places right ⇒ exponent −3 | |
| 101.001 | point moved 2 places left ⇒ exponent +2 | |
| 10.11 | moved 1 place left ⇒ exponent +1 | |
| −101.001101 | sign is carried along untouched |
Move the point left → exponent goes up. Move it right → exponent goes down.
3. The two formats
Single precision — one word, 32 bits
Double precision — two words, 64 bits
| Sign | Exponent | Significand | Bias | |
|---|---|---|---|---|
| Single | 1 | 8 | 23 | 127 |
| Double | 1 | 11 | 52 | 1023 |
4. The master formula ★
Three things are quietly happening in that formula. Understand all three:
(a) The sign bit
0 = positive, 1 = negative. That's it — it is not two's complement.
(b) The hidden leading 1
Every normalized number starts 1. — so storing that 1 would waste a bit. It is implied. If the significand field holds 1001…, the real significand is . That's why the formula says .
(c) The biased exponent
Why bias instead of two's complement? Because the exponent field then sorts naturally: all-0s is the smallest exponent and all-1s the largest, so plain integer comparison of the bit patterns compares the floating-point values. Bias is 127 (single) / 1023 (double).
5. Converting the fraction to binary
Whole part: repeated division by 2. Fractional part: repeated multiplication by 2, recording the integer digit that pops out each time, read top to bottom.
0.3125 × 2 = 0.625 → 0 0.625 × 2 = 1.25 → 1 0.25 × 2 = 0.50 → 0 0.5 × 2 = 1.00 → 1 (fraction hit 0, stop) Read top → bottom: 0.3125₁₀ = .0101₂ So 11.3125₁₀ = 1011.0101₂
.11 and 0.3125 = 0.25 + 0.0625 = .0101. 6. Packing: decimal → IEEE 754 ★
- Convert the decimal to binary.
- Normalize it: .
- Stored exponent = , converted to binary.
- Write sign · exponent · the
yydigits, then pad with zeros to fill the field.
Example 1 — represent −0.75 in single precision (slide 62)
1. decimal → binary: −0.75 = −0.11 2. normalize: −0.11 = −1.1 × 2⁻¹ ⇒ real exponent = −1 3. stored exponent: 127 + (−1) = 126 = 01111110₂ 4. sign = 1 (negative) significand field = the digits after "1." = 1, padded with zeros 1 01111110 10000000000000000000000
Example 2 — represent −10.75 in single AND double precision (slide 67)
1. decimal → binary: −10.75 = −1010.11 2. normalize: −1010.11 = −1.01011 × 2³ ⇒ real exponent = 3 3a. SINGLE exponent = 127 + 3 = 130 = 10000010₂ 3b. DOUBLE exponent = 1023 + 3 = 1026 = 10000000010₂ 4. sign = 1 ; significand digits = 01011, then zeros SINGLE (32 bits): 1 10000010 01011000000000000000000 DOUBLE (64 bits): 1 10000000010 0101100000000000000000000000000000000000000000000000
01011 are identical — double just pads with more zeros. So always solve single first, then re-bias for double. 7. Unpacking: IEEE 754 → decimal ★
Run the formula backwards. Given 1 01111110 10000000000000000000000:
sign = 1 → negative
exponent = 01111110 = 126 → real exponent = 126 − 127 = −1
significand field = 1000… → significand = .1 → (1 + .1) = 1.1
value = (−1)¹ × 1.1 × 2⁻¹
= −1.1 × 2⁻¹
= −0.11 (shift the point one place right)
Now .11 in decimal: 2⁻¹ + 2⁻² = 0.5 + 0.25 = 0.75
value = −0.75 ✔1. in front of the significand field. (5) shift the binary point by the exponent. (6) convert the binary fraction to decimal by adding columns. 8. Special values
Some exponent patterns are reserved rather than being ordinary numbers:
| Single exponent | Single fraction | Double exponent | Object represented |
|---|---|---|---|
| 0 | 0 | 0 | 0 (sign bit may be 0 or 1) |
| 0 | nonzero | 0 | ± denormalized number |
| 1–254 | anything | 1–2046 | ± ordinary floating-point number |
| 255 | 0 | 2047 | ± infinity |
| 255 | nonzero | 2047 | NaN (Not a Number) |
- Zero is special-cased — the hidden leading 1 means the format can't otherwise express 0. Exponent all-0 and fraction all-0 ⇒ the value is 0.
- ±∞ lets software continue past a divide-by-0 instead of taking an interrupt; the program just prints ∞.
- NaN is the result of genuinely invalid operations like or . Its purpose is to let programmers postpone tests and decisions to a convenient point later in the program.
9. Overflow and underflow
Underflow — a negative exponent grows too large (too negative) to fit.
Both can raise interrupts, exactly like integer overflow. The slide's examples:
OVERFLOW 1.1 × 2¹²⁸ + 1.1 × 2¹²⁸ ----------- 11.0 × 2¹²⁸ = 1.1 × 2¹²⁹ stored exponent would be 129 + 127 = 256 — cannot fit in 8 bits. UNDERFLOW 1.111 × 2⁻¹²⁶ − 1.1 × 2⁻¹²⁶ --------------- 0.011 × 2⁻¹²⁶ = 1.1 × 2⁻¹²⁸ stored exponent would be −128 + 127 = −1 — the exponent field holds only non-negative values, so this cannot be represented.
Both failures are the same failure: after normalizing the result, the biased exponent fell outside .
- Write the formula from memory.
- 1/8/23 with bias 127 · 1/11/52 with bias 1023.
- Normalize to — the leading 1 is hidden.
- Add the bias when packing, subtract it when unpacking.
- Know the 5 special-value rows and the overflow/underflow definitions.