I know how to add or subtract floating point numbers in binary. For multiplication and division I have to multiply/divide the mantissas and add/subtract the exponents.
But here is something I don't understand. Mantissas are fractions, I only learned how to multiply and divide integers. What rules apply to mantissas arithmetic? I have seen some examples in which multiplying mantissas were treated as integers, but, for division, what happens to the remainder? Can somebody provide an example of mantissa division?
(The preferred term is “significand.” “Mantissa” is a legacy term from the days of paper tables of logarithms.)
Examples of adding three-bit significands:
1.01
+1.11
_____
11.00
Result >= 10.00, so shift to 1.100, round to 1.10, and add one to exponent.
1.00
+1.11
_____
10.11
Result >= 10.00, so shift to 1.011, round to 1.10, and add one to exponent.
Examples of subtracting three-bit significands:
1.01
-1.10
Note the latter value is larger in magnitude, so swap
them and remember to invert the sign of the result later.
1.10
-1.01
_____
0.01
Result < 1.00, so shift to 1.00 and subtract two from exponent.
Example of multiplying three-bit significands:
1.01
*1.10
_______
.0000
.101
+1.01
_______
1.1110
Result is in range, so do not shift. Rounding
requires rounding up, producing 10.0, which is
>= 10.0, so shift to 1.00 and add one to exponent.
Note that, in these examples, the significands of the numbers being added and subtracted were already aligned. That happens when the exponents of the numbers being added are equal. If they are not, one of the numbers has to be shifted to make its exponent equal to the other, and then the significands can be added or subtracted.
Division is done with the same long division you learned in school. You carry out the division to as many digits as needed for your significand, and then you use the remainder at that point to decide whether to round up or down.