COA Notes
IEEE 754 floating-point standard, single precision, double precision, special values, and rounding modes.
Introduction
Before 1985, every computer manufacturer had their own floating-point format — IBM had one, DEC had another, Cray had a third. Programs would produce different results on different machines! The IEEE 754 standard, published in 1985 (revised 2008 and 2019), fixed this chaos by defining a universal floating-point format. Today, virtually every processor — from smartphones to supercomputers — implements IEEE 754.
The Standard Formats
Single Precision (32 bits) — float in C/Java
| S | Exponent | Mantissa |
|---|---|---|
| 1b | 8 bits | 23 bits |
- Sign: 1 bit
- Exponent: 8 bits, bias = 127
- Mantissa: 23 bits (24 bits effective with hidden bit)
- Range: ±1.18×10⁻³⁸ to ±3.4×10³⁸
- Precision: ~7 decimal digits
Double Precision (64 bits) — double in C/Java
| S | Exponent | Mantissa |
|---|---|---|
| 1b | 11 bits | 52 bits |
- Sign: 1 bit
- Exponent: 11 bits, bias = 1023
- Mantissa: 52 bits (53 bits effective with hidden bit)
- Range: ±2.23×10⁻³⁰⁸ to ±1.8×10³⁰⁸
- Precision: ~15-16 decimal digits
Encoding Rules
Normal Numbers (most common)
- Exponent: 1 to 254 (single) or 1 to 2046 (double) — not all 0s or all 1s
- Value = (-1)^S × 1.Mantissa × 2^(Exponent - Bias)
- The leading 1 is implicit (hidden bit)
Denormalized Numbers (subnormal)
- Exponent: all zeros (0)
- Value = (-1)^S × 0.Mantissa × 2^(1 - Bias)
- The leading bit is 0 (not 1) — no hidden bit
- Allows gradual underflow toward zero
Zero
- Exponent: all zeros
- Mantissa: all zeros
- +0 (sign=0) and -0 (sign=1) are both valid and compare equal
Infinity
- Exponent: all ones (255 or 2047)
- Mantissa: all zeros
- +∞ (sign=0) and -∞ (sign=1)
- Results from overflow or division by zero
NaN (Not a Number)
- Exponent: all ones
- Mantissa: non-zero
- Quiet NaN (qNaN): Propagates through operations without signaling
- Signaling NaN (sNaN): Triggers an exception when used
Worked Examples
Example 1: Represent +1.5 in Single Precision
- 1.5₁₀ = 1.1₂ (1 + 0.5)
- Already normalized: 1.1 × 2⁰
- Sign = 0, Exponent = 0 + 127 = 127 = 01111111₂, Mantissa = 10000...0
- Result: 0 01111111 10000000000000000000000
- Hex: 0x3FC00000
Example 2: Represent -0.375 in Single Precision
- 0.375₁₀ = 0.011₂ (0.25 + 0.125)
- Normalize: 1.1 × 2⁻²
- Sign = 1, Exponent = -2 + 127 = 125 = 01111101₂, Mantissa = 10000...0
- Result: 1 01111101 10000000000000000000000
- Hex: 0xBEC00000
Example 3: Decode 0x41200000
- Binary: 0 10000010 01000000000000000000000
- Sign = 0 (positive)
- Exponent = 10000010₂ = 130, Actual = 130-127 = 3
- Mantissa = 1.01 (with hidden bit)
- Value = 1.01 × 2³ = 1010.0₂ = 10.0₁₀
- Result: +10.0
Rounding Modes
IEEE 754 defines four rounding modes:
- Round to Nearest, Even (default): Round to the nearest representable value. If exactly halfway, round to the value with an even last bit. This is the most common mode and minimizes average error.
- Round Toward +∞ (ceiling): Always round up
- Round Toward -∞ (floor): Always round down
- Round Toward Zero (truncation): Always round toward zero
The "round to nearest, even" default is carefully chosen to prevent systematic bias in repeated calculations.
Precision Limits
What Can Be Represented Exactly?
- Integers up to 2²⁴ (16,777,216) in single precision
- Integers up to 2⁵³ (9,007,199,254,740,992) in double precision
- Fractions that are sums of negative powers of 2: 0.5, 0.25, 0.125, 0.375, etc.
What Cannot Be Represented Exactly?
- 0.1, 0.2, 0.3 (repeating binary fractions)
- Integers larger than 2²⁴ (single) or 2⁵³ (double)
- Irrational numbers (π, e, √2)
Machine Epsilon
The smallest value ε such that 1.0 + ε ≠ 1.0:
- Single precision: ε ≈ 1.19 × 10⁻⁷
- Double precision: ε ≈ 2.22 × 10⁻¹⁶
Exception Handling
IEEE 754 defines five exception conditions:
- Overflow: Result too large → ±∞
- Underflow: Result too small → denormalized or zero
- Division by zero: → ±∞
- Invalid operation: → NaN (e.g., 0/0, √-1, ∞-∞)
- Inexact: Result was rounded (happens very frequently)
Key Takeaways
- IEEE 754 standardized floating-point across all platforms — same format, same results
- Single precision: 1+8+23 = 32 bits, ~7 decimal digits of precision
- Double precision: 1+11+52 = 64 bits, ~15 decimal digits of precision
- The biased exponent and hidden bit are key design features
- Special encodings handle ±0, ±∞, NaN, and denormalized numbers
- Not all decimal numbers can be represented exactly — this is inherent, not a bug
- The standard defines rounding modes and exception handling for predictable behavior
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for IEEE 754 Standard.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Computer Organization & Architecture topic.
Search Terms
computer-organization, computer organization & architecture, computer, organization, data, representation, ieee, 754
Related Computer Organization & Architecture Topics