Floating point numbers can only be added or subtracted once their exponents are the same, in the same way that the decimal points must line up before two denary numbers are added.
Adding Floating Point Numbers
- 1.Compare the exponents. If they differ, raise the smaller exponent to match the larger one, shifting that mantissa one place right for each 1 added to its exponent.
- 2.Add the mantissas. The exponent stays the same.
- 3.Normalise the answer if its mantissa does not start 01 or 10.
Both numbers have an 8-bit mantissa and a 4-bit exponent.
| Step | Mantissa | Exponent |
|---|---|---|
| 5.5 | 01011000 | 0011 (3) |
| 1.25 | 01010000 | 0001 (1) |
| 1.25 with its exponent raised to 3 (mantissa 2 places right) | 00010100 | 0011 (3) |
| Add the mantissas: 01011000 + 00010100 | 01101100 | 0011 (3) |
The answer starts 01, so it is already normalised.
Subtracting Floating Point Numbers
Subtraction is done by adding a negative number. Line up the exponents, take the two's complement of the mantissa being subtracted, then add.
| Step | Mantissa | Exponent |
|---|---|---|
| 5.5 | 01011000 | 0011 (3) |
| 3.5 | 01110000 | 0010 (2) |
| 3.5 with its exponent raised to 3 (mantissa 1 place right) | 00111000 | 0011 (3) |
| Two's complement of that mantissa, giving -3.5 | 11001000 | 0011 (3) |
| Add: 01011000 + 11001000, ignoring the carry out | 00100000 | 0011 (3) |
| Normalise: mantissa 1 place left, exponent down by 1 | 01000000 | 0010 (2) |
• When a negative mantissa is shifted right to raise its exponent, the places on the left are filled with 1s so that it stays negative. Mantissa 10110000 with exponent 1 becomes 11101100 with exponent 3: both are -1.25
• Shifting a mantissa right can push bits off the end. Those bits are lost, so the answer can lose precision
• Never add the exponents. Make them equal first, then add only the mantissas
• Show each stage: matching the exponents, the addition, then normalising
• Check the answer by converting all three numbers to denary