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.

  1. First, convert the two representations to scientific notation. Thus, we explicitly represent the hidden 1.
  2. 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.
  3. Multiply the mantissa of X to the mantissa of Y. Call this result m.
  4. 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.
  5. Add the sign bits, mod 2, to get the sign of the resulting multiplication.
  6. 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:

  1. 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.

  2. 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

  3. Multiply the mantissa of X to the mantissa of Y. Call this result m.

    Multiplying 1.01 by 1.11 results in 10.0011

  4. 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

  5. Add the sign bits, mod 2, to get the sign of the resulting multiplication.

    The sign bit is 0 + 0 = 0.

  6. 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