Binary & Floats — Trivia & Interesting Facts¶
Surprising, historical, and little-known facts about binary representation and floating-point arithmetic.
The Patriot missile failure that killed 28 soldiers was caused by a floating-point error¶
On February 25, 1991, a Patriot missile battery in Dhahran, Saudi Arabia, failed to intercept an incoming Iraqi Scud missile because of a floating-point rounding error. The system clock multiplied time by 1/10, which cannot be represented exactly in binary. After 100 hours of uptime, the accumulated error was 0.34 seconds — enough for the Scud to travel 687 meters past the tracking gate.
IEEE 754 floating-point has 2,143,289,344 different representations of NaN¶
In the 64-bit double-precision format, any value with all exponent bits set to 1 and a non-zero fraction is NaN (Not a Number). This means there are over 2 billion distinct bit patterns that all represent "not a number," and NaN is famously not equal to itself: NaN != NaN evaluates to true in every IEEE 754 compliant language.
0.1 + 0.2 does not equal 0.3 in most programming languages¶
The expression 0.1 + 0.2 == 0.3 evaluates to false in JavaScript, Python, Java, C, Ruby, and virtually every language that uses IEEE 754 floating-point. The actual result is 0.30000000000000004. This is because 0.1, 0.2, and 0.3 all have infinite binary representations, so they must be rounded when stored in finite-width floating-point formats.
The Vancouver Stock Exchange lost $25 per point to a rounding bug¶
In 1982, the Vancouver Stock Exchange introduced a new stock index initialized at 1,000. The index was recalculated after each transaction and truncated to three decimal places instead of rounded. After 22 months, the index read 524.811 — roughly half its correct value of 1,098.892. The accumulated truncation error had silently destroyed the index's accuracy.
Binary was not the first choice for computers¶
Early computers used decimal (base-10) arithmetic hardware. ENIAC (1945) used 10-position ring counters, and IBM's early machines used Binary-Coded Decimal (BCD). John von Neumann argued forcefully for binary in his 1945 "First Draft" report, noting that binary circuits were simpler and more reliable. The industry gradually shifted, but BCD persisted in financial systems into the 2020s.
A signed 32-bit integer overflow caused a $460 million trading loss in 45 minutes¶
On August 1, 2012, Knight Capital deployed buggy trading software that sent millions of erroneous orders to the NYSE. While the root cause was a deployment error, the incident illustrates how numeric edge cases in financial software can be catastrophic. Knight Capital lost $460 million in 45 minutes and had to be rescued from bankruptcy the following week.
The Y2K bug was essentially a 2-digit decimal overflow problem¶
The Year 2000 problem existed because programmers stored years as two decimal digits to save memory (which cost roughly $1 per kilobyte in the 1960s). The estimated worldwide cost of Y2K remediation was $300-600 billion. The decision to save a few bytes per record in the 1960s created one of the most expensive software bugs in history.
Denormalized floats can make programs run 100x slower¶
IEEE 754 defines "denormalized" (or "subnormal") numbers for values very close to zero. On many CPUs, operations on denormalized floats are handled by microcode traps rather than hardware, running 10-100x slower than normal float operations. Game developers and audio engineers have been bitten by this — a value slowly decaying toward zero can suddenly tank performance.
The Ariane 5 rocket exploded because of a 64-bit to 16-bit integer conversion¶
On June 4, 1996, the Ariane 5 rocket self-destructed 37 seconds after launch because the inertial navigation system converted a 64-bit floating-point number to a 16-bit signed integer, causing an overflow. The value was the horizontal velocity, which was larger than Ariane 4 had ever experienced. The software had been reused from Ariane 4 without updating the numeric ranges. The rocket and its payload were worth $370 million.
Computers represent negative numbers using a trick from mechanical calculators¶
Two's complement, the standard way computers represent negative integers, was inherited from mechanical calculator techniques dating back to the 1800s. The method works by subtracting from the maximum representable value plus one — the same principle that makes an odometer reading 99999 equivalent to -1 when it rolls over.