Multiplying Floating Point Numbers
Introduction
We'll do addition using the one byte
floating point representation discussed in the other class notes.
IEEE 754 single precision has so many bits to work with, that
it's simply easier to explain how floating point addition works
using a small float representation.
Multiplication is simple. Suppose you want to multiply two floating
point numbers, X and Y.
Here's how to multiply floating point numbers.
- First, convert the two representations to scientific notation.
Thus, we explicitly represent the hidden 1.
- Let x be the exponent of X. Let y be the
exponent of Y. The resulting exponent (call it z) is
the sum of the two exponents. z may need to be adjusted
after the next step.
- Multiply the mantissa of X to the mantissa of Y.
Call this result m.
- If m is does not have a single 1 left of the radix
point, then adjust the radix point so it does, and adjust
the exponent z to compensate.
- Add the sign bits, mod 2, to get the sign of the resulting
multiplication.
- Convert back to the one byte floating point representation,
truncating bits if needed.
Example
Let's multiply the following two numbers:
| Variable |
sign |
exponent |
fraction |
| X |
0 |
1001 |
010 |
| Y |
0 |
0111 |
110 |
Here are the steps again:
- First, convert the two representations to
scientific notation. Thus, we explicitly represent the hidden
1.
In this case, X is 1.01 X 22 and
Y is 1.11 X 20.
- Let x be the exponent of X. Let y be the
exponent of Y. The resulting exponent (call it z) is
the sum of the two exponents. z may need to be adjusted
after the next step.
For now, the resulting exponent is 2 + 0 = 2
- Multiply the mantissa of X to the
mantissa of Y. Call this result m.
Multiplying 1.01 by 1.11 results in 10.0011
- If m is does not have a single 1
left of the radix point, then adjust the radix point so it
does, and adjust the exponent z to
compensate.
Now, we have to renormalize 10.0011 to 1.00011
and increase the exponent by 1 to 3
- Add the sign bits, mod 2, to get the sign
of the resulting multiplication.
The sign bit is 0 + 0 = 0.
- Convert back to the one byte floating
point representation, truncating bits if needed.
We need to truncate 1.00011 x 23 to
1.000 x 23 and convert.
| Product |
sign |
exponent |
fraction |
| X * Y |
0 |
1010 |
000 |
Negative Values
Unlike floating point addition, negative values are simple to
take care of in floating point multiplication. Treat the sign
bit as 1 bit UB, and add modulo 2. This is the same as XORing
the sign bit.
Bias
Does the bias representation help us in floating point multiplication?
In multiplication, it's more of a pain to use bias representation
because we need to sum the exponents. Adding exponents represented
in bias notation requires special hardware for biased representation.
You're better off converting to two's complement, and adding.
Thus, the bias makes it more challenging to add exponents.
Summary
Multiplying two floating point values isn't so difficult, at least,
if you're mostly interested in understanding how it works, rather
than developing hardware to do the multiplication.
Multiplying floating point requires you to add the exponents of
two values, then multiply the mantissas, then renormalize that
result, adjusting the exponent if necessary. Finally, you deal
with the sign bit by XORing the sign bit.
Multiplying in real hardware involves rounding, dealing with
overflow and underflow. Our goal is to be able to do the
multiplication on paper, just to get an idea of what's going on.
Web Accessibility