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 ( kg) to the distance to the nearest galaxy ( 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 to . Suppose a scientist needs to represent (Avogadro’s number). A plain 32-bit integer cannot reach it. Neither can a 64-bit integer ( is still too small), and even a 128-bit integer (), which has the range, has no way to represent the fractional part of .
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 with a resolution of . 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 to 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:
where is the sign bit (0 for positive, 1 for negative), is the fraction (the explicit bits of the significand), and is the biased exponent. The leading in 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.
| Name | Bits | Sign | Exponent | Fraction | Bias | Sig bits |
|---|---|---|---|---|---|---|
| Half (binary16) | 16 | 1 | 5 | 10 | 15 | 11 |
| Single (binary32) | 32 | 1 | 8 | 23 | 127 | 24 |
| Double (binary64) | 64 | 1 | 11 | 52 | 1023 | 53 |
| Quad (binary128) | 128 | 1 | 15 | 112 | 16383 | 113 |
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.
| Exponent | Fraction | Meaning |
|---|---|---|
| (positive or negative zero) | ||
| Denormal (subnormal) number | ||
| NaN (Not a Number) |
Zeros. IEEE 754 has both and . They compare as equal () but produce different results when used as divisors: and .
Denormals (subnormals). When the exponent field is zero and the fraction is nonzero, the implicit leading bit is instead of , and the true exponent is (not ). 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 .
Infinities. Infinities result from overflow (a finite computation that exceeds the maximum representable value) or from explicit division by zero. They propagate through arithmetic: , .
NaN (Not a Number). NaN results from mathematically undefined operations: , , . 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:
-
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 . This avoids systematic bias in long computation chains.
-
Round toward (ceiling). Always round toward positive infinity.
-
Round toward (floor). Always round toward negative infinity.
-
Round toward zero (truncation). Always round toward zero.
-
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:
-
Guard bit (). The first bit beyond the target precision.
-
Round bit (). The second bit beyond the target precision.
-
Sticky bit (). 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:
-
Exponent comparison. Compute the difference of the two exponents . The number with the smaller exponent must be shifted.
-
Alignment shift. Shift the significand of the smaller-exponent operand right by positions, filling the vacated positions with zeros and tracking the shifted-out bits in the sticky bit.
-
Significand addition or subtraction. Add (or subtract, if the signs differ) the aligned significands using a fixed-point adder.
-
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 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:
-
Sign. The result sign is .
-
Exponent. Add the true exponents: .
-
Significand. Multiply the two significands (including the implicit leading bits) using the integer multiplier of Chapter 7. The product of two -bit significands is a -bit value.
-
Normalization. The product is either or (at most one bit of right shift is needed). Adjust the exponent if the product’s integer part is .
-
Rounding. Round the -bit product to 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 bits. For double precision it is 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 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 (the reciprocal square root) via the iteration , and the final result 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 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 -bit product is not rounded before being fed into an adder that adds the third operand . The unrounded product has 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 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:
-
E4M3: 1 sign, 4 exponent, 3 fraction bits. Larger significand for better precision.
-
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]IEEE (2019). “IEEE.” IEEE. doi:10.1109/IEEESTD.2019.8766229