Skip to main content
Home › Categories › Artificial Intelligence & Computing › Computer Number Formats: Binary, IEEE 754 Floating-Point, BF16, and FP8 AI Arithmetic

Computer Number Formats: Binary, IEEE 754 Floating-Point, BF16, and FP8 AI Arithmetic

Author: ZUVDEX Team 4 min read
ieee 754 floating point bf16 fp8 fp64 fp32 fp16 bfloat16 comparison fp8 e4m3 e5m2 microscaling mxfp4 catastrophic cancellation rounding error two complement signed integers mixed precision loss scaling

Every numerical calculation in scientific computing, financial ledgers, and deep neural networks maps real numbers onto finite bit widths. While exact financial accounting uses fixed-point decimal integers and Two’s Complement signed integers, scientific simulation and artificial intelligence rely on binary floating-point formats—evolving from William Kahan’s IEEE 754 64-bit/32-bit standards into specialized reduced-precision AI formats (`BF16`, `FP8 E4M3/E5M2`, and block-scaled `MXFP4`) that multiply throughput four- to sixteen-fold on modern silicon.

Key Highlights

  • Binary floating-point encodes numbers as (−1)^sign × 1.mantissa × 2^(exponent − bias): Exponent bits control dynamic range (largest/smallest representable magnitude), while Mantissa bits control precision.
  • Standard `FP16` (5 exponent, 10 mantissa bits) overflows above `65,504`, requiring loss scaling in training; `BFloat16` (`BF16`: 8 exponent, 7 mantissa bits) matches `FP32`’s massive `±3.4 × 10³⁸` range as a drop-in replacement.
  • Modern `FP8` splits into `E4M3` (more precision for forward weights/activations) and `E5M2` (wider dynamic range for backward gradients), while Open Compute `MXFP8`/`MXFP4`/`NVFP4` attach shared micro-block scale factors.
  • Base-2 fractions cannot represent base-10 `0.1` finitely—causing `0.1 + 0.2 = 0.30000000000000004` in IEEE 754; financial balances must ALWAYS store integer minor units (cents/paisa) or exact `NUMERIC`/`Decimal` types.

Comparing FP64, FP32, FP16, BF16, FP8, and INT4 Bit Layouts

Deep neural networks exhibit remarkable resilience to mantissa quantization noise during matrix multiplication—provided two invariants hold: activations and gradients must not overflow/underflow dynamic range, and dot-product partial sums must accumulate into wide `FP32` registers inside the Tensor Core before rounding back down.

That physical insight explains why Google Brain designed `BFloat16` by truncating the bottom 16 mantissa bits of an `FP32` float while keeping all 8 exponent bits intact: neural pretraining runs smoothly without the fragile dynamic loss-scaling gymnastics required by narrow-exponent IEEE `FP16`.

Format Bits (Sign–Exp–Mantissa) Max Positive Value Primary Computing Workload
FP64 (Double) 64 (1 – 11 – 52) ~1.8 × 10³⁰⁸ Orbital mechanics, CFD aerodynamics, finite-element physics
FP32 (Single) 32 (1 – 8 – 23) ~3.4 × 10³⁸ Master optimizer weights, LayerNorm/Softmax, graphics shaders
FP16 (Half) 16 (1 – 5 – 10) 65,504 (narrow!) Mobile/Apple GPUs & inference where dynamic range is bounded
BF16 (BFloat16) 16 (1 – 8 – 7) ~3.4 × 10³⁸ Universal default for LLM & multimodal mixed-precision training
FP8 (E4M3 / E5M2) 8 (1–4–3 / 1–5–2) 448 / 57,344 (+ tile scales) 2× faster Hopper/Blackwell Tensor Core training & high-QPS serving
MXFP4 / INT4 4 bits + block scale Group/micro-block scaled 4× weight compression for edge & high-density LLM inference

Avoiding NaN Propagation, Catastrophic Cancellation, and Softmax Overflow

Under IEEE 754 rules, `NaN` ("Not a Number", produced by `0.0 / 0.0` or `∞ − ∞`) is infectious: a single `NaN` inside one corrupted training row contaminates every weight in a billion-dollar cluster within one optimizer step, and `NaN == NaN` evaluates to `False`! Mature numerical code shifts softmax inputs by subtracting `max(z)` prior to exponentiation (`exp(z_i − z_max)`), accumulates reductions in `FP32`/`FP64`, and checks `isfinite()` invariants.

  • Always keep sensitive reductions—Softmax, RMSNorm variance, RoPE trig frequencies, and AdamW master weights—in FP32 even during FP8/BF16 runs.
  • Never test floating-point equality with `a == b`; compare `abs(a – b) <= atol + rtol * abs(b)`.
  • Store monetary ledger columns as `BIGINT` minor units or SQL `NUMERIC(19, 4)`—never `FLOAT` or `DOUBLE`.

FAQs

Why does `0.1 + 0.2` equal `0.30000000000000004` in Python, JavaScript, C++, and Rust?

Just as `1 / 3` repeats infinitely in base 10 (`0.3333...`), `1 / 10` (`0.1`) repeats infinitely in base 2 (`0.0001100110011...₂`); rounding both operands to 53 binary significand bits leaves a tiny `2⁻⁵⁴` residual visible when printed to 17 decimal digits.

Why does FP8 use two different formats (`E4M3` and `E5M2`) instead of just one?

Forward weights and normalized activations benefit from the extra mantissa bit of `E4M3` (3 mantissa bits), whereas backward loss gradients span much wider dynamic ranges across layers and need the extra exponent bit of `E5M2` (5 exponent bits).

References & Sources

  • Goldberg, David (1991) — What Every Computer Scientist Should Know About Floating-Point Arithmetic, ACM Computing Surveys, 23(1), 5–48.
  • IEEE Standard 754-2019 — IEEE Standard for Floating-Point Arithmetic.
  • Micikevicius, Paulius et al. (2022) — FP8 Formats for Deep Learning, NVIDIA / Arm / Intel Specification, arXiv:2209.05433.