Floating point is a method of storing numbers in binary that separates each number into a sign, a mantissa (the significant digits), and an exponent (the scale). This allows computers to represent both astronomically large numbers and vanishingly small fractions using a fixed number of bits.
Why is fixed-point representation not always enough?
In fixed-point representation, the binary point is anchored at a fixed position — for example, always after bit 4. This is fast and simple, but the range of numbers you can represent is limited by where the point is fixed.
Suppose you have 8 bits with the point after bit 4: you can represent values from 0000.0000 (0) to 1111.1111 (15.9375). That range is fine for a temperature sensor, but useless for storing the distance to a star (measured in trillions of kilometres) and an electron's mass (approximately 0.00000000000000000000000000000091093837015 kg) in the same program.
Floating point solves this by letting the binary point "float" — shifting left and right as needed, just like scientific notation in maths.
What is the floating point format?
Floating point splits a bit pattern into three fields:
| Field | Purpose | Analogy |
|---|---|---|
| Sign bit | 0 = positive, 1 = negative | The ± in front of a number |
| Exponent | How far to shift the binary point | The power of 10 in scientific notation |
| Mantissa | The significant digits | The digits in scientific notation |
Think of scientific notation: 3.14 × 10⁶. The mantissa is 3.14, the exponent is 6, and implicitly the sign is positive. Floating point works identically, but in base 2.
The international standard is IEEE 754. A 32-bit single-precision float allocates:
- 1 bit for the sign
- 8 bits for the exponent (stored with a bias of 127)
- 23 bits for the mantissa
A 64-bit double-precision float allocates 1 + 11 + 52 bits, giving greater range and precision. Programming languages typically use double-precision for float or double variables.
How does the mantissa–exponent pair represent a number?
Normalised form ensures the mantissa always starts with a leading 1 (for non-zero numbers), which maximises precision. The leading 1 is so predictable that IEEE 754 omits it — the hardware adds it back mentally — gaining one free bit of precision.
Worked example (simplified 8-bit format for teaching): 1-bit sign, 3-bit exponent, 4-bit mantissa.
Suppose the bit pattern is: 0 101 1010
- Sign = 0 → positive
- Exponent = 101₂ = 5, but stored with a bias of 3, so real exponent = 5 − 3 = 2
- Mantissa = 1.1010₂ (implicit leading 1 added) = 1 + 0.5 + 0.125 = 1.625
Value = +1.625 × 2² = +6.5
What is precision, and why does it matter?
The mantissa determines how many significant digits you can store. A 23-bit mantissa gives approximately 7 decimal significant figures; a 52-bit mantissa gives about 15 to 16.
This means floating point is an approximation. The number 0.1 cannot be represented exactly in binary floating point — the nearest 32-bit float is approximately 0.100000001490116. For most purposes this does not matter, but in financial calculations (where 0.1 + 0.2 = 0.30000000000000004 in many languages) it can introduce real errors.
What is the trade-off between range and precision?
Allocating more bits to the exponent increases range (the spread from the smallest to the largest representable number). Allocating more bits to the mantissa increases precision (how accurately a value within that range can be stored). With a fixed total number of bits, you cannot have both.
| Format | Sign | Exponent | Mantissa | Approx range | Approx precision |
|---|---|---|---|---|---|
| 32-bit single | 1 | 8 | 23 | ±3.4 × 10³⁸ | ~7 decimal digits |
| 64-bit double | 1 | 11 | 52 | ±1.8 × 10³⁰⁸ | ~15–16 decimal digits |
What are rounding errors and overflow in floating point?
Rounding error: when a real number cannot be represented exactly, the stored value is the nearest representable float. Repeated arithmetic operations can compound these small errors into significant inaccuracies.
Overflow: the result of a calculation exceeds the maximum representable value. IEEE 754 signals this as the special value Inf (infinity).
Underflow: the result is smaller than the minimum representable non-zero value, and it is rounded to zero.
Frequently asked questions
Do I need to know IEEE 754 bit patterns for GCSE?
At GCSE you need to understand the concept of floating point: sign, mantissa, exponent, their roles, and the trade-off between range and precision. Most GCSE mark schemes do not require you to apply the IEEE 754 bias formula. However, A-level Computer Science (AQA, OCR) does require working with normalised binary floating point representations, so a solid GCSE understanding is an excellent foundation.
Why does 0.1 + 0.2 not equal 0.3 in Python?
Because 0.1 and 0.2 cannot be represented exactly in binary floating point. The nearest 64-bit doubles to each are stored instead, and when added, the result is 0.30000000000000004. This is a feature (or limitation) of the floating point standard, not a Python bug — the same result occurs in every language that uses IEEE 754 doubles. Exact decimal arithmetic requires a different approach, such as Python's decimal module.
What is the difference between floating point and fixed point?
Fixed point stores a number with a binary point at a fixed position, giving constant range and precision — simple but inflexible. Floating point stores a sign, mantissa, and exponent, allowing the binary point to shift and represent a vastly wider range of values at the cost of slightly more hardware complexity and the possibility of rounding errors.
When would a programmer choose 32-bit over 64-bit floating point?
A programmer uses 32-bit (single precision) when memory or speed matters more than precision — for example in 3D graphics, where millions of vertex coordinates are processed every frame and a slight imprecision in position is invisible. A programmer uses 64-bit (double precision) when accuracy is critical — scientific simulations, financial modelling, or any calculation where small errors compound over millions of iterations.
Bring your floating point practice questions to Professor Turing at aitutors.me — worked examples with immediate feedback make the mantissa click.