The idea: multiply the three fields one by one

A single-precision float is ±1.f × 2e − 127: a sign bit, an 8-bit biased exponent e and a 23-bit fraction f with a hidden 1 in front. Multiplying two such numbers is easier than adding them. There is no need to line the binary points up first. The three parts are handled one by one: multiply the signs, add the powers of two, multiply the significands. Then the result is put back into the 32-bit format, and that is where the work is: normalizing and rounding.

The fields of A and B feed three units: an XOR gate for the sign, an adder that computes eA plus eB minus 127, and a 24 by 24 bit multiplier for the significands; the product is normalized, which may add 1 to the exponent; the exponent is range checked, the significand is rounded to nearest even, and sign, exponent and fraction form the result
Both operands feed three independent units; normalizing and rounding then fix up the exponent and the significand.

The page runs the five steps of the MIPS instruction mul.s $f0, $f2, $f4. Pick A and B in the menus and press Multiply, or run a demo. The operands are fixed bit patterns, shown in hex and in their three fields. How a float is stored, and how floats are added, is on Number Systems: Two's Complement, Fixed Point and IEEE 754.

Steps 1 and 2: sign and exponent

The sign of the product is the XOR of the two sign bits: plus times plus and minus times minus give plus. In Demo: −3 × 0.1 the signs are 1 and 0, so the product is negative.

The powers of two multiply by adding their exponents. But each stored field is the real exponent plus 127. Adding the two fields adds the bias twice, so the hardware subtracts 127 once: e = eA + eB − 127. Demo: 1.5 × 2.5 = 3.75:

Operandhexsignexponent fieldvalue
A = 1.53FC000000127 (20)1.12 × 20
B = 2.5402000000128 (21)1.012 × 21
A × B407000000 XOR 0 = 0127 + 128 − 127 = 1281.1112 × 21 = 3.75

Step 3: a 48-bit product

Each fraction gets its hidden 1 back, so both significands are 24 bits wide. They go into an ordinary unsigned integer multiplier: 24 × 24 bits give a 48-bit product. The circuit is the same kind as on Multiply and Divide Hardware, just wider and much faster.

Both significands are in [1, 2), so the product is in [1, 4). Read as a number, it has two bits before the binary point. For 1.5 × 2.5 the product is 01.1110 0000 …, that is 1.875, and 1.875 × 21 = 3.75.

Step 4: normalize

A normalized float starts with 1. If the top bit of the product is 1, the product is 2 or more. The hardware shifts it right one place and adds 1 to the exponent. One shift is always enough, because the product is below 4. Addition is different: there, the sum can lose many leading bits and need a long left shift.

Demo: 3 × 3 = 9: 1.12 × 1.12 = 10.01 = 2.25. After the shift it is 1.0012, and the exponent 128 + 128 − 127 = 129 becomes 130. The result is 1.125 × 23 = 9 = 41100000.

Step 5: round to nearest even with G, R and S

The normalized product has 48 bits, but only 24 fit: the hidden 1 and 23 fraction bits. The rest is cut off, and three bits remember what was cut off. The guard bit G is the first bit that does not fit, the round bit R is the next one, and the sticky bit S is the OR of all the bits after R: it is 1 if any of them is 1.

A normalized significand: 24 kept bits ending in the last bit, then G, R and the rest, whose OR is S; a table: G equal 0 rounds down, G equal 1 with R or S equal 1 rounds up, G equal 1 with R and S equal 0 is a tie that goes to the even neighbour
G says whether the cut-off part is at least half of the last place; R and S say whether it is more than half.

The default IEEE 754 mode, round to nearest, ties to even, picks the closer of the two floats around the exact product. Only an exact tie needs a rule: then it picks the float whose last bit is 0. Ties go up half the time and down half the time, so long sums do not drift.

  • Demo: −3 × 0.1: 0.1 is stored as 3DCCCCCD, already a little too big. The product 10.0110 0110 … is shifted, and then G R S = 1 1 0: more than half. The hardware adds 1 at the last bit. The result is BE99999A = −0.300000012, while the exact product of the two stored values is −0.300000004470.
  • Demo: tie, round up to even: 1.5 × 1.00000012 (= 1 + 2−23, 3F800001). The exact product 1.5 + 1.5 × 2−23 sits halfway between two floats. G R S = 1 0 0 and the last kept bit is 1, so the tie goes up to 3FC00002, whose last bit is 0.
  • Demo: tie, stay at even: 1.5 × 1.00000036 (3F800003). Again G R S = 1 0 0, but the last kept bit is already 0. The bits are just dropped: 3FC00004.

In multiplication, R and S could even be one bit: the only shift is to the right, so the rule only asks "is G 1?" and "is anything after G 1?". Addition needs R separately, because there a left shift can pull G back into the result. An FPU keeps all three and shares the rounding logic.

When rounding carries all the way

Adding 1 at the last bit can ripple through a run of ones. If every kept bit is 1, the significand 1.111…1 becomes 10.000…0 = 2. The hardware then normalizes a second time: shift right once more and add 1 to the exponent. Demo: rounding carries to 2.0: 1.99999976 (= 2 − 2−22, 3FFFFFFE) × 1.00000012 is 2 − 2−45. The kept bits are 24 ones and G R S = 1 1 1, so the result rounds up to exactly 2.0 = 40000000, with the exponent 127 + 1 = 128.

Overflow and underflow

A normal float has a biased exponent from 1 to 254. The exponent of the product can leave that range at either end.

A number line of the biased exponent: 0 and below is underflow, 1 to 254 is a normal float, 255 and above is overflow; 2 to the minus 100 squared lands at minus 73, 1.5 times 2.5 at 128, and 2 to the 127 times 2 at 255
Only biased exponents 1 to 254 give a normal float; outside that range the product overflows or underflows.
  • Overflow: 255 or more. With round to nearest the result is ±∞ (exponent field 255, fraction 0), and the overflow flag is set. Demo: 2127 × 2: 254 + 128 − 127 = 255, so the result is +∞ = 7F800000, although the exact product 2128 ≈ 3.4028237 × 1038 is only a little above the biggest float, 3.4028235 × 1038.
  • Underflow: 0 or less. The result is too small for a normal float. The hardware shifts the significand right until the exponent field can be 0, which gives a denormal 0.f × 2−126, and then rounds. Demo: 2−100 × 2−100: 27 + 27 − 127 = −73, so the significand would move 74 places right. Every 1 bit lands in the sticky bit, G = 0, and the result is 0 = 00000000. The exact product 2−200 is far below the smallest denormal, 2−149 ≈ 1.4 × 10−45.

In MIPS: mul.s and mul.d

MIPS keeps floats in coprocessor 1, which has its own registers $f0 … $f31.

InstructionWhat it does
mul.s $f0, $f2, $f4single precision: $f0 = $f2 × $f4, rounded
mul.d $f0, $f2, $f4double precision on register pairs: 53-bit significands, 106-bit product, bias 1023
lwc1, swc1load and store a float between memory and an $f register

A C statement float c = a * b; becomes one mul.s. Overflow and underflow do not stop the program by default: the result is ±∞ or a tiny number or 0, and a flag in the floating-point control register (FCSR) records what happened. Traps can be turned on in the same register.

See also Number Systems: Two's Complement, Fixed Point and IEEE 754 for the float format, floating-point addition and the four rounding modes, and Multiply and Divide Hardware for the shift-and-add multiplier that step 3 builds on.

See also Float Formats: FP32, FP16, BF16 and FP8 for the same fields in shorter formats, and Arithmetic Circuits for the array multiplier that does all the adds at once.

See also The Floating-Point Adder: IEEE 754 add.s Hardware for the other half of an FPU, where the sum must be aligned first and a leading-zero counter undoes cancellation.

What the page leaves out

  • Special inputs: 0, ±∞, NaN and denormal operands. Real hardware checks for them first (0 × ∞ is NaN, for example). The menus offer only normal numbers.
  • The other three rounding modes (toward 0, +∞ and −∞). They use the same G, R and S, with different rules.
  • Double precision, division, square root and the fused multiply-add, which rounds a × b + c only once.
  • How the 24 × 24 multiplier is built: real FPUs use Booth recoding and trees of carry-save adders, and finish in a few cycles.
  • The exact moment underflow is flagged ("tininess before or after rounding"), and the inexact flag.

On the mind map

This page on the Computer Architecture mind map · 76 pages in 7 branches · open it to see the whole map and test yourself in recall mode.