Data Representation
Floating-point numbers: how a computer stores fractions, and why it sometimes gets them slightly wrong.
//The idea in one sentence
The number is stored as mantissa × 2^exponent, exactly like standard form in maths but in base 2. Both parts are held in two's complement.
mantissa 01000000 = +0.5
exponent 00000011 = +3
value = 0.5 × 2³ = 0.5 × 8 = 4//Why normalise
Without a rule, the same value could be stored many different ways, and leading zeros in the mantissa waste bits that could have held real digits. Normalising fixes both: one representation per value, and maximum precision. A normalised positive mantissa always begins 0.1; a negative one always begins 1.0.
//Mantissa vs exponent — the trade-off
With a fixed total number of bits, giving more to the mantissa means more PRECISION (more accurate values) but a smaller RANGE. Giving more to the exponent means a bigger RANGE (larger and smaller magnitudes) but less precision. Exams ask you to state both sides.
//Rounding and truncation errors
Some fractions cannot be represented exactly in binary — 0.1 in denary is a recurring binary fraction, just as 1/3 recurs in denary. The stored value is therefore slightly wrong, and repeated calculations make the error grow. This is why money is often stored as integer numbers of the smallest unit rather than as floating point.
KEY TERMS
CHECK YOURSELF
1.Why is a floating-point number normalised?
2.More bits given to the exponent means: