Best afterA comparison is a yes/no value

Roundoff

Decimals like 0.1 have no exact representation in binary, the same way 1/3 has no exact decimal. So 0.1 + 0.2 lands a hair off 0.3, and asking == 0.3 returns False. This is roundoff — a representation error — and it is a different beast from overflow, which is a fixed-width wrap.

Add 0.1 + 0.2 and check whether the result equals 0.3.

Roundoff — when 0.1 + 0.2 isn't 0.3 execution-derived · CPython
4    result = "exact match"5else:
variables
state after line 1 runs
variablevalue
total0.30000000000000004

notetotal is 0.1 + 0.2 — but look closely: it is 0.30000000000000004, not 0.3. Neither 0.1 nor 0.2 has an exact binary fraction, so the sum lands a hair off.

step 1 / 4

Click a line, drag the slider, or use the keys.

What you are looking at

Both versions compute total = 0.1 + 0.2, and both show the same surprising value:0.30000000000000004. The difference is how they compare it.

Every state you see came from running the program under CPython's tracer at build time — see how GlassBox stays honest.