Part IArchitectural Foundations

Floating-Point Arithmetic

August 3, 2026·18 min read·beginner

This chapter develops the IEEE 754 floating-point standard from first principles: the encoding of sign, exponent, and significand into a fixed-width bit pattern, the special values (zeros, infinities, NaNs…

Integer arithmetic handles whole numbers. Scientific computation, graphics, machine learning, and signal processing demand numbers with fractional parts and a dynamic range spanning many orders of magnitude: from the mass of an electron (9.1×10319.1 \times 10^{-31} kg) to the distance to the nearest galaxy (2.5×10222.5 \times 10^{22} m). No fixed-width integer format can cover that range without wasting almost all of its bits on unused positions. The solution is floating-point representation, where the radix point moves (“floats”) under the control of an exponent field, concentrating the available bits around the significant digits of the value.

This chapter develops the IEEE 754 floating-point standard from first principles: the encoding of sign, exponent, and significand into a fixed-width bit pattern, the special values (zeros, infinities, NaNs, denormals), the five rounding modes, and the hardware that adds, multiplies, divides, and fuses multiply-add operations on floating-point operands. It closes with a survey of the newer reduced-precision formats (BFloat16, FP8, TensorFloat-32) that are reshaping machine-learning hardware.

01.Why Floating Point?

A 32-bit unsigned integer can represent values from 00 to 23214.3×1092^{32} - 1 \approx 4.3 \times 10^{9}. Suppose a scientist needs to represent 6.02×10236.02 \times 10^{23} (Avogadro’s number). A plain 32-bit integer cannot reach it. Neither can a 64-bit integer (2641.8×10192^{64} \approx 1.8 \times 10^{19} is still too small), and even a 128-bit integer (21283.4×10382^{128} \approx 3.4 \times 10^{38}), which has the range, has no way to represent the fractional part of 6.02214076×10236.02214076 \times 10^{23}.

Fixed-point arithmetic places the radix point at a predetermined position within the integer, dedicating some bits to the integer part and the remaining bits to the fractional part. A 32-bit Q16.16 format, for example, gives 16 integer bits and 16 fractional bits, covering the range [0,65535][0, 65535] with a resolution of 2161.5×1052^{-16} \approx 1.5 \times 10^{-5}. Fixed point is fast (it uses the same adder and multiplier as integer arithmetic) but inflexible: the programmer must choose the radix point position at design time, and values that fall outside the chosen range overflow silently.

Floating-point representation separates the question of range from the question of precision. A 32-bit IEEE 754 single-precision number covers a range from roughly ±1.2×1038\pm 1.2 \times 10^{-38} to ±3.4×1038\pm 3.4 \times 10^{38} with about 7 decimal digits of precision. The cost is more complex hardware for every arithmetic operation, since the exponents must be aligned before addition and renormalized after every operation.

02.The IEEE 754 Standard

The IEEE 754 standard [1] defines the encoding, arithmetic, and exception model for floating-point computation. Before IEEE 754, every manufacturer had its own floating-point format and rounding rules, making it impossible to port numerical software between machines and expect the same results. The standard was first published in 1985, revised in 2008 to add decimal formats and fused multiply-add, and revised again in 2019 with minor clarifications.

Binary encoding

An IEEE 754 binary floating-point number is stored as three fields packed into a fixed-width word:

value=(1)s×1.f×2ebias\text{value} = (-1)^{s} \times 1.f \times 2^{e - \text{bias}}

where ss is the sign bit (0 for positive, 1 for negative), ff is the fraction (the explicit bits of the significand), and ee is the biased exponent. The leading 11 in 1.f1.f is implicit and is not stored, gaining one extra bit of precision for free.

Table 1. IEEE 754 binary formats. “Sig bits” counts the implicit leading 1 plus the explicit fraction bits.

NameBitsSignExponentFractionBiasSig bits
Half (binary16)1615101511
Single (binary32)32182312724
Double (binary64)6411152102353
Quad (binary128)12811511216383113

Special values

IEEE 754 reserves two exponent-field patterns for special values:

Table 2. Special value encoding in IEEE 754. e_{} denotes the all-ones exponent field.

ExponentFractionMeaning
0000±0\pm 0 (positive or negative zero)
000\neq 0Denormal (subnormal) number
emaxe_{\max}00±\pm \infty
emaxe_{\max}0\neq 0NaN (Not a Number)

Zeros. IEEE 754 has both +0+0 and 0-0. They compare as equal (+0=0+0 = -0) but produce different results when used as divisors: 1/(+0)=+1 / (+0) = +\infty and 1/(0)=1 / (-0) = -\infty.

Denormals (subnormals). When the exponent field is zero and the fraction is nonzero, the implicit leading bit is 00 instead of 11, and the true exponent is 1bias1 - \text{bias} (not 0bias0 - \text{bias}). This creates a set of evenly spaced values between zero and the smallest normal number, preventing an abrupt gap (called the “underflow gap”) around zero. Denormal arithmetic is slower on many processors because the hardware datapath is optimized for the normal case where the leading bit is 11.

Infinities. Infinities result from overflow (a finite computation that exceeds the maximum representable value) or from explicit division by zero. They propagate through arithmetic: +5=\infty + 5 = \infty, ×(3)=\infty \times (-3) = -\infty.

NaN (Not a Number). NaN results from mathematically undefined operations: 0/00 / 0, \infty - \infty, 1\sqrt{-1}. IEEE 754 distinguishes quiet NaN (qNaN), which propagates through computations without raising an exception, from signaling NaN (sNaN), which raises an invalid-operation exception when used as an operand.

Rounding

The exact result of a floating-point operation can have more significant bits than the destination format provides. The result must be rounded to the nearest representable value. IEEE 754 defines five rounding modes:

  1. Round to nearest, ties to even (default). If the exact result is equidistant between two representable values, round to the one whose least significant bit is 00. This avoids systematic bias in long computation chains.

  2. Round toward ++\infty (ceiling). Always round toward positive infinity.

  3. Round toward -\infty (floor). Always round toward negative infinity.

  4. Round toward zero (truncation). Always round toward zero.

  5. Round to nearest, ties away from zero. If equidistant, round away from zero. Required only for decimal formats.

To implement rounding, the hardware computes three extra bits beyond the target precision:

  1. Guard bit (GG). The first bit beyond the target precision.

  2. Round bit (RR). The second bit beyond the target precision.

  3. Sticky bit (SS). The OR of all remaining bits beyond the round bit. The sticky bit records whether any precision was lost, which is needed to break ties.

03.Floating-Point Addition and Subtraction

Adding two floating-point numbers is more involved than adding two integers because the exponents must be aligned before the significands can be added.

The hardware pipeline for floating-point addition has four stages:

  1. Exponent comparison. Compute the difference of the two exponents Δ=eAeB\Delta = e_{A} - e_{B}. The number with the smaller exponent must be shifted.

  2. Alignment shift. Shift the significand of the smaller-exponent operand right by Δ|\Delta| positions, filling the vacated positions with zeros and tracking the shifted-out bits in the sticky bit.

  3. Significand addition or subtraction. Add (or subtract, if the signs differ) the aligned significands using a fixed-point adder.

  4. Normalization and rounding. If the result’s leading bit is not in the expected position, shift the result left or right (adjusting the exponent accordingly) until the leading 11 is in the implicit-bit position. Then round using the guard, round, and sticky bits.

The alignment shifter is a barrel shifter (from Chapter 5) whose shift amount is the exponent difference. For double precision, this is a 52-position barrel shifter, which is a significant piece of hardware. The normalization step uses a leading-zero counter followed by a left-shift, both of which also use barrel-shifter-like structures.

04.Floating-Point Multiplication

Floating-point multiplication is structurally simpler than addition because no alignment shift is needed. The algorithm is:

  1. Sign. The result sign is sAsBs_{A} \oplus s_{B}.

  2. Exponent. Add the true exponents: eresult=(eAbias)+(eBbias)+bias=eA+eBbiase_{\text{result}} = (e_{A} - \text{bias}) + (e_{B} - \text{bias}) + \text{bias} = e_{A} + e_{B} - \text{bias}.

  3. Significand. Multiply the two significands (including the implicit leading bits) using the integer multiplier of Chapter 7. The product of two pp-bit significands is a 2p2p-bit value.

  4. Normalization. The product 1.xxx×1.yyy1.xxx \times 1.yyy is either 1.zzz1.zzz or 10.zzz10.zzz (at most one bit of right shift is needed). Adjust the exponent if the product’s integer part is 1010.

  5. Rounding. Round the 2p2p-bit product to pp bits using the guard, round, and sticky bits.

The significand multiplication reuses the same Booth-recoded Wallace or Dadda tree multiplier described in Chapter 7. For single precision the significand multiplier is 24×2424 \times 24 bits. For double precision it is 53×5353 \times 53 bits. In many processor designs the same physical multiplier serves both integer and floating-point operations, with a mux selecting the appropriate input and output widths.

05.Floating-Point Division and Square Root

Floating-point division computes A/BA / B by dividing the significands and subtracting the exponents. The significand division uses the SRT or Newton-Raphson algorithm from Chapter 7, with the exponent handling layered on top.

Square root is structurally similar to division. An SRT-like algorithm (sometimes called a “digit-recurrence” square root) retires one or two root bits per cycle by maintaining a partial radicand and updating it with trial subtractions. Newton-Raphson can also compute 1/x1 / \sqrt{x} (the reciprocal square root) via the iteration yn+1=12yn(3xyn2)y_{n+1} = \frac{1}{2} y_{n}(3 - x \cdot y_{n}^{2}), and the final result x=x(1/x)\sqrt{x} = x \cdot (1/\sqrt{x}) requires one additional multiplication.

Division and square root are the slowest floating-point operations. A typical latency is 10 to 30 cycles for double precision, compared with 3 to 5 cycles for multiply and 3 to 4 cycles for add. Because divisions are relatively rare in most workloads (typically 1 to 3 percent of floating-point instructions), most processors use an iterative non-pipelined divider that occupies less area than a fully pipelined unit.

06.Fused Multiply-Add

The fused multiply-add (FMA) computes a×b+ca \times b + c as a single operation with a single rounding step at the end. Without the FMA, the computation would require a separate multiply (with rounding) followed by a separate add (with rounding), for two rounding errors instead of one.

The FMA is the single most important floating-point instruction in modern processors. It is the primitive for dot products, matrix multiplications, polynomial evaluations (Horner’s method), and Newton-Raphson iterations. Every major ISA provides an FMA instruction: FMADD in RISC-V, FMADD in ARMv8, VFMADD in x86-64 AVX/FMA.

The hardware for an FMA is essentially a multiplier whose 2p2p-bit product is not rounded before being fed into an adder that adds the third operand cc. The unrounded product has 2p2p bits of precision, so the adder and alignment shifter must handle a wider intermediate value than a standalone floating-point adder. The single rounding step at the end produces a result that is correctly rounded as if computed to infinite precision and then rounded once.

07.Reduced-Precision and Emerging Formats

The standard IEEE 754 formats (binary16, binary32, binary64, binary128) were designed for scientific and general-purpose computation where accuracy matters. Machine-learning training and inference have different requirements: the workload is dominated by matrix multiplications, the individual values are noisy (they come from stochastic gradient descent), and throughput matters more than per-element precision. This has driven the creation of several reduced-precision formats that sacrifice significand bits for smaller hardware and higher throughput.

BFloat16

BFloat16 (Brain Floating Point 16) is a 16-bit format with 1 sign bit, 8 exponent bits, and 7 explicit fraction bits, giving 8 significand bits once the implicit leading 11 is counted. It has the same exponent range as binary32 (8-bit exponent, bias 127) but less than half the significand precision (8 vs 24 bits). The advantage is that any binary32 value can be converted to BFloat16 by simply truncating the lower 16 bits of the significand, which makes hardware conversion trivial.

BFloat16 is supported by Google TPUs, Intel AMX, ARM SME, AMD CDNA, and NVIDIA Ampere and later architectures.

FP8 formats

FP8 refers to a family of 8-bit floating-point formats proposed for machine-learning inference. Two variants are common:

  1. E4M3: 1 sign, 4 exponent, 3 fraction bits. Larger significand for better precision.

  2. E5M2: 1 sign, 5 exponent, 2 fraction bits. Larger exponent range for better dynamic range.

NVIDIA Hopper implements both E4M3 and E5M2 in its Tensor Cores, using E4M3 for the forward pass (where precision matters) and E5M2 for the backward pass (where gradient magnitudes vary widely).

TensorFloat-32

TensorFloat-32 (TF32) is a 19-bit format used internally by NVIDIA Ampere and later Tensor Cores. It has 1 sign bit, 8 exponent bits, and 10 fraction bits. TF32 is not a storage format. Tensor Cores accept binary32 inputs, internally truncate the significand to 10 bits, multiply in TF32, and accumulate in binary32. The effect is the dynamic range of binary32 with the throughput of a format roughly the size of binary16.

Fixed point revisited

For inference on edge devices (phones, microcontrollers, IoT sensors), even FP8 can be too expensive. Quantized inference uses 8-bit or 4-bit integers (INT8, INT4) with per-tensor or per-channel scale factors. The arithmetic is plain integer multiplication and addition, which is the cheapest possible hardware. The scale factors are floating-point but are applied once per tensor, not per element. ARM Cortex-M processors, RISC-V cores with the vector extension and its widening integer multiply-accumulate operations, and dedicated NPU accelerators (Chapter 96) rely heavily on quantized integer inference.

08.Looking Ahead

This chapter has developed the IEEE 754 floating-point representation and the hardware for addition, multiplication, division, and fused multiply-add. Together with the integer arithmetic of Chapter 7, the arithmetic unit of a processor is now complete. The next chapter steps down one level of abstraction, from the gate-level and block-level circuits of Chapters 4 through 8 to the CMOS transistors that implement those gates in silicon.

09.Worked Examples

10.Exercises

References

  1. [1]IEEE (2019). “IEEE.” IEEE. doi:10.1109/IEEESTD.2019.8766229
Book mode
computer-architecturearchitectural-foundations
Was this helpful?