CIE AS & A Level Computer Science, section 13.3 (Floating-point numbers, representation and manipulation)
Precision and range
| Increase the | Effect |
|---|---|
| mantissa bits | greater precision (more significant digits, smaller rounding errors) |
| exponent bits | greater range (larger and smaller numbers can be stored) |
With a fixed total number of bits, there is a trade-off: more bits for one means fewer for the other.
Rounding errors
Many numbers cannot be stored exactly, because the mantissa has a limited length. For example, in binary is a recurring fraction, so only an approximation is stored. The difference is a rounding error, and repeated calculations can make it grow.
Overflow
Overflow is when a result is too large to be stored, because the exponent is not big enough. The answer is wrong, or an error occurs.
Underflow
Underflow is when a result is too close to zero to be stored, because the exponent is too negative. It is usually stored as zero.
Choosing the number of bits
- For very accurate scientific results, use more mantissa bits.
- For numbers over a wide range, such as astronomy, use more exponent bits.
- Equality tests on real numbers should be avoided.
Common mistake: saying more exponent bits increase precision. The exponent controls the range; the mantissa controls the precision. Also, do not test real numbers with = because of rounding errors.
Exam tip: when asked about overflow or underflow, state what is too large or small and which part (the exponent) is the limit. For rounding, say the value is stored as an approximation.
Check yourself
What increases the range of numbers that can be stored?
More bits for the exponent.
Why might 0.1 + 0.2 not equal 0.3 on a computer?
0.1 and 0.2 cannot be stored exactly in binary, so rounding errors make the sum slightly different.
What is overflow?
When a result is too large to be represented with the available bits.