Log inStart free
LESSON 6.06 · 6 STAGES · 3 CONTROLS · 3 CHECKSPRO · PREVIEW

Floating-point formats

Watch one number squeeze into six float formats and lose digits on the way.


Pro lesson. Stage 1 is free to watch. Pro opens all 6 stages, 3 controls and 3 checks, in this lesson and every other.

Go Pro · $8.25/mo
EXPLAINER · 6.06 · FLOAT BAYFP16 · 1 + 5 + 10 = 16 BITS
01
Stage 1 of 6 · Six layouts
Each dtype splits its bits into a sign, exponent bits and a mantissa. FP16 uses 1 + 5 + 10 = 16 bits.
Explain it simply

Each row is one number format, drawn bit by bit. The first bit is the sign. The ochre bits pick a power of two, and the teal bits hold the digits. More ochre bits give more range, and more teal bits give more digits.

Six rows of bits, one per format: FP64, FP32, TF32, BF16, FP16 and FP8. FP16 has 1 sign bit, 5 exponent bits and 10 mantissa bits.

value · mantissa bitsexponent bits · rangestored numbersrounding error · overflowsubnormal · not stored
FP64torch.float64FP32torch.float32TF32matmul modeBF16torch.bfloat16FP16torch.float16FP8torch.float8_e4m3fnsix float layoutsFP16 = 1 sign + 5 exponent + 10 mantissa = 16 bitsFP64torch.float64FP32torch.float32TF32matmul modeBF16torch.bfloat16FP16torch.float16FP8torch.float8_e4m3fnsix float layoutsFP16 = 1 sign + 5 exponent + 10 mantissa = 16 bits
Toy: 4 values in 6 formats, a 3-logit softmax
STAGE 1 / 6
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
x=(−1)s⋅2e⋅1.mx = (-1)^{\sy{s}{ink}{s}} \cdot 2^{\sy{e}{param}{e}} \cdot \sy{m}{data}{1.m}
FP16:1+5+10=16 bits\text{FP16}: 1 + 5 + 10 = 16 \text{ bits}

A float is a sign, a power of two and a fraction.

Common mix-ups

MYTHBF16 is more precise than FP16 because it is newer.

The fix, and 1 more mix-up with the diagram to show them, come with Pro.

Predict, then reveal
3 CHECKS · PRO
Q01In FP16, what happens to 70000?

Make your guess, then test it in the diagram. All 3 checks come with Pro.

PRO LESSON · YOU WATCHED STAGE 1 OF 6
Unlock the full explainer
  • 5 more stages and 3 live controls
  • 2 mix-up cards and 3 predict-then-reveal checks
  • Watch it as a narrated video, in three voices
  • Every Pro lesson and capstone · 656 in total

$99 a year, or $15 a month. Cancel any time.