Thought Toys · Computation & information · Exhibit 82
Ask any computer for 0.1 + 0.2 and it answers 0.30000000000000004. It isn't sloppy and it isn't broken. There is no such number as 0.1 inside it to add in the first place — only the nearest thing it can build out of halves, quarters and eighths.
One tenth, in binary, cut to the machine's precision bits kept bits thrown away what you asked for
—
—
—
A computer stores a number the way you'd write it in binary: as a sum of halves, quarters, eighths, sixteenths. That works perfectly for 0.5, for 0.25, for 0.75. It does not work for 0.1. In base two, one tenth is 0.0001100110011… with 1100 repeating forever — the same way one third is 0.3333… in the base we happen to use. There is no place to stop that lands on the number you meant.
So the machine stops anyway, at whatever precision it has, and keeps the nearest value it can build. That's the top panel: the bright digits are kept, the dim ones are thrown away, and the arrow shows the rounding. Drag the precision slider. The stored value chases 0.1 and never catches it — at 4 bits or at 53, and, as the note below records, not at 1024 either.
The middle panel is the part people find hard to believe. Those evenly spaced ticks are every number the machine can hold near your answer; between them there is nothing at all. Your exact answer — the ring — usually falls between two ticks, so it gets pushed to one. When 0.1 and 0.2 are each pushed, and their sum is pushed again, the result can land on the tick next door to the nearest one to 0.3. One tick apart is all it takes for a comparison to say no.
And the bottom strip is the honest coda. Try the precisions one by one and the failure blinks on and off: at some widths this sum comes out right, at others it doesn't, and it isn't tidily fixed by using more bits. 53 — the width in every browser, phone and spreadsheet you own — happens to be one of the widths where it doesn't.
improve/verify/82-floating-point.js, 44 checks). The model is
an independent toy float built on exact BigInt rationals that never performs a floating-point operation, and
it reproduces this machine's doubles bit for bit: 0.1, 0.2, 0.3, 1/3, 0.01 and 400 random doubles
all round-trip unchanged. So what you're dragging is the same object your browser uses, not a story about it.
Also in Computation & information: Noise sets a speed limit, not an accuracy limit. →
← the cabinet · Thought Toys — a cabinet of explorable explanations. Exhibit 82.