Skip to main content

Command Palette

Search for a command to run...

Why Your Computer Can Launch Rockets But Can't Add 0.1 + 0.2

Published
4 min read
Why Your Computer Can Launch Rockets But Can't Add 0.1 + 0.2

Your computer can render entire universes in video games, predict tomorrow's weather, and help billionaires land rockets on floating robot ships. Yet somehow, if you innocently ask it to add 0.1 + 0.2, it looks you dead in the eye and says "0.30000000000000004."

Congratulations, computer. You had one job.

Why Computers Are Insanely Fast (The Good News)

Computers are speed demons because they're basically very confident idiots. They only understand two things: ON and OFF. That's it. Just 1s and 0s, yes and no, hot dog or not hot dog.

This beautiful simplicity means they can make billions of decisions per second without breaking a sweat. No deep thinking required—just flip switches really, really fast. It's like being great at your job because your job is literally just turning a light switch on and off. Hard to mess that up, right?

Right?

The Math Problem Nobody Saw Coming

Here's where our speedy friend becomes that one person who's confidently wrong about everything. While whole numbers translate perfectly into binary (5 is just 101 in computer-speak), fractions get... creative.

In our normal decimal world, some fractions work great: 1/2 = 0.5, easy peasy. Others don't: 1/3 = 0.33333... forever. We've made peace with this.

But in binary, it's a completely different set of numbers that become infinite nightmares. The number 0.1 (one-tenth) seems perfectly innocent to us, but to a computer, it's like asking them to write out π to the last digit. It becomes 0.0001100110011... repeating forever into the digital void.

So when you ask a computer to store 0.1, it's like asking someone to hold water in their hands. They get close, but not exact. And when you add two slightly-wrong numbers together? You get a confidently-wrong answer.

When Math Errors Get Serious

Usually these tiny errors are harmless. Your computer thinks 0.1 + 0.2 = 0.30000000000000004? Who cares, close enough for jazz.

But then there's the 1991 Gulf War Patriot missile incident. The system's clock accumulated floating-point errors over 100 hours—only 0.34 seconds total, no big deal. Except when you're tracking missiles, 0.34 seconds means you're looking for the missile half a kilometer away from where it actually is. The result was catastrophic: 28 soldiers killed because a computer couldn't keep time accurately.

Imagine explaining to someone that a multimillion-dollar defense system failed because of the digital equivalent of "ehh, close enough."

Banks had similar wake-up calls. Small rounding errors across millions of transactions can make money mysteriously vanish (or appear). Nothing says "professional financial institution" like telling customers their money disappeared into the floating-point void.

Three Rules So You Don't Become a Meme

1. Never trust computers with exact decimal equality

Checking if price == 19.99 is like trusting a toddler with scissors. Instead, check if numbers are "close enough": abs(price - 19.99) < 0.01. Or just work in whole cents like a reasonable person.

2. Money deserves better than floating-point

Use special decimal libraries for financial calculations. Your accountant will thank you. Your lawyer will thank you. The people who aren't suing you will thank you.

3. This isn't a bug, it's a choice

Floating-point numbers were designed to handle everything from atomic particles to galaxy distances in limited memory. The tradeoff is precision. Engineers knew this. They chose speed and range over perfection. It works brilliantly for 99% of use cases—just not for the simple stuff we learned in second grade.

The Bottom Line

Your computer is simultaneously a mathematical genius and that friend who insists they're "basically right" when they're objectively wrong. It can calculate the trajectory of a spacecraft to Mars, but it will confidently tell you that 0.1 + 0.2 equals something with 17 decimal places.

And honestly? That's kind of beautiful in a chaotic way.

So next time your code spits out 0.30000000000000004, just remember: your computer is doing its best, working in a number system designed by humans who thought "how hard could decimal fractions be?" The answer, as it turns out, was "surprisingly hard."

Welcome to programming. We're all just managing chaos with style.