Encode this number
1
Level 1
you are the FPU, compute
catastrophic cancellation
coming soon

Two nearly-equal numbers, both already rounded on the way in, walk into a subtraction.
The leading bits annihilate and the rounding dust gets promoted to the front of the number.

Finish Operations Level 3 first. It ends right at this cliff edge.

float8 (E4M3)

float8 packs a real number into a single byte, 8 bits. Under the hood it's just scientific notation, in binary.

Decimal scientific notation writes a number as its significant digits (one nonzero digit, a point, then the rest) times a power of ten: e.g. 6.022 × 1023, where 6.022 are the digits that carry the value and 1023 sets the scale. float8 (E4M3) does the same in base 2, splitting its 8 bits into 1 sign, the significant digits (the mantissa), and the power of two (the exponent):

value = ±1.mmm × 2e−7

The 3 mantissa bits are the digits after the point. The leading 1 is always there, so it isn't stored. The 4 exponent bits set the scale: they are read as a number 0–15, then 7 is subtracted, giving powers from 2−6 up to 28.

One exception: when the exponent bits are all zero, the leading digit flips to 0 and the scale pins to its smallest, 2−6:

value = ±0.mmm × 2−6

That's how float8 reaches 0 (all bits zero) and the tiny values between 0 and 2−6. At the top end, value = ±448 (exponent 1111, mantissa 110), and value = NaN (exponent 1111, mantissa 111).

Try it out

Toggle the bits and watch the value react.

Specification

8 bits: 1 sign · 4 exponent (bias 7) · 3 mantissa.
value = 1.mmm × 2e−7. The leading 1 is implicit.
value = 0.mmm × 2−6. Zero or subnormal, when exponent is 0000.
value = ±448. Max magnitude, when exponent is 1111 and mantissa 110.
value = NaN, when exponent is 1111 and mantissa 111.

Shortcuts
spacesign asdfexponent jklmantissa backspacereset

operations: you are the FPU

Every float8 add or subtract runs the same pipeline. Here you run it, one stage at a time. The machine only checks your work.

1 · align. Rewrite the smaller number at the larger exponent. The whole significand shifts right, one place per exponent step, and the leading 1 moves too. Keep every bit: this step is lossless.
2 · add / subtract. Ordinary binary arithmetic on the aligned significands. Still exact.
3 · normalize & round. Slide the point back to 1.something, adjust the exponent, and keep 3 mantissa bits. The dropped tail decides:

first dropped bit 0  →  round down (just truncate)
first dropped bit 1, more 1s after  →  round up (add 1 ULP)
exactly 100… (half a ULP)  →  tie → go to the neighbor whose last bit is 0

4 · encode. Write the result as float8 bits.

Level 1 · alignment & exact sums. Level 2 · rounding, ties & swamping. Level 3 · subtraction: borrowing & vanishing leading bits.