Every programmer sooner or later types 0.1 + 0.2 into a REPL and gets back 0.30000000000000004. It looks like a bug, but it is the deliberate behavior of IEEE 754, the standard that governs floating-point arithmetic on virtually every chip made since 1985.
The problem it solves is fundamental: real numbers are infinite in count and can have infinite decimal expansions, but a computer register is finite — just 64 bits for a double-precision float. IEEE 754 chooses a clever encoding that covers an enormous range (from roughly 5 × to 1.8 × ) by sacrificing exactness for most values.
The result is a system where 1.0, 2.0 and 0.5 are represented perfectly, but 0.1 is not — because 0.1 in binary is a repeating fraction, just as 1/3 is in decimal. The standard was designed and championed by William Kahan (University of California, Berkeley), who received the Turing Award in 1989 largely for this work. It has been proven optimal in the sense that no other fixed-width binary format achieves the same precision guarantees.
Understanding IEEE 754 is not just trivia. It is the first step toward numerical stability — knowing when to trust a floating-point result and when to rewrite your algorithm to avoid catastrophic cancellation.
Comments
Loading comments...