SOLID STATE PRESS
← Back to catalog
Floating Point: Why 0.1 + 0.2 Isn't 0.3 cover
Coming soon
Coming soon to Amazon
This title is in our publishing queue.
Browse available titles
Computer Science

Floating Point: Why 0.1 + 0.2 Isn't 0.3

IEEE 754, Rounding Error, and the Bits Behind Every Decimal — A TLDR Primer

You typed 0.1 + 0.2 into a console and got 0.30000000000000004. Now what? This primer explains exactly why that happens and what to do about it — without sending you down a rabbit hole of computer architecture textbooks.

Written for high school and early-college students meeting this for the first time in a CS class, a coding bootcamp, or a job interview, the book walks through how computers actually store fractional numbers in binary, why decimals like 0.1 turn into repeating expansions the same way 1/3 does in base 10, and how the IEEE 754 standard packs a number into sign, exponent, and mantissa fields. From there it covers machine epsilon, why rounding error can quietly grow or suddenly explode through cancellation, and the practical coding rules that keep it from wrecking your program — never compare floats with ==, use tolerances, keep money in integers, and know when to reach for a Decimal or fractions library.

A closing chapter tours the real-world stakes: the Patriot missile clock drift, the Ariane 5 crash, jittery game physics, and the scientific-computing bugs that make this one of the most common interview questions in software engineering. No filler, no derivations you'll never use — just the concrete model you need to reason about floating point correctly.

Ideal as a computer science exam prep guide, a quick refresher before a coding interview, or a plain-language answer for a parent trying to understand why their kid's homework code gives weird decimals.

Stop guessing why your numbers don't add up — get the short version that actually explains it.

What you'll learn
  • Explain why 0.1 + 0.2 evaluates to 0.30000000000000004 in most programming languages
  • Decode a number stored in IEEE 754 single- or double-precision format
  • Distinguish rounding error, machine epsilon, and catastrophic cancellation
  • Compare floating-point numbers safely using tolerance-based checks
  • Recognize when to use integers, decimals, or arbitrary-precision libraries instead of floats
What's inside
  1. 1. The 0.1 + 0.2 Problem
    Open with the famous surprise, show it in real code, and set up the question the rest of the book answers.
  2. 2. Binary Fractions: Why Some Decimals Don't Fit
    Explain how fractions work in base 2, why 0.1 becomes a repeating binary expansion, and draw the analogy to 1/3 in base 10.
  3. 3. IEEE 754: How a Float Is Actually Stored
    Walk through the sign, exponent, and mantissa fields of single- and double-precision floats, with a fully decoded example.
  4. 4. Rounding, Machine Epsilon, and Error That Grows
    Introduce round-to-nearest-even, machine epsilon, and how errors accumulate or explode through cancellation.
  5. 5. Writing Code That Survives Floating Point
    Practical rules: never use == on floats, use tolerances, prefer integers for money, and know when to reach for Decimal or fractions libraries.
  6. 6. Where This Matters: From Games to Rockets
    Short tour of real-world consequences — Patriot missile failure, Ariane 5, graphics jitter, scientific computing — and why every programmer eventually meets this bug.
Published by Solid State Press
Floating Point: Why 0.1 + 0.2 Isn't 0.3 cover
TLDR STUDY GUIDES

Floating Point: Why 0.1 + 0.2 Isn't 0.3

IEEE 754, Rounding Error, and the Bits Behind Every Decimal — A TLDR Primer
Solid State Press

Contents

  1. 1 The 0.1 + 0.2 Problem
  2. 2 Binary Fractions: Why Some Decimals Don't Fit
  3. 3 IEEE 754: How a Float Is Actually Stored
  4. 4 Rounding, Machine Epsilon, and Error That Grows
  5. 5 Writing Code That Survives Floating Point
  6. 6 Where This Matters: From Games to Rockets
Chapter 1

The 0.1 + 0.2 Problem

Open a Python interpreter, JavaScript console, or nearly any programming language and type this:

>>> 0.1 + 0.2
0.30000000000000004

That extra 0000000000000004 isn't a typo, a display bug, or a joke. It's the honest answer your computer gives, and once you understand why, you'll understand something fundamental about how every computer on Earth handles fractional numbers.

Here's the setup. A floating-point number is the standard way computers represent numbers that aren't whole — numbers with a decimal point, like 0.1, 3.14, or 2.71828. "Floating" refers to the fact that the decimal point can slide around to represent very large numbers (like 6.02 × 10²³) or very small ones (like 0.0000001), similar to how scientific notation works. Nearly every programming language — Python, JavaScript, C, Java, Swift — uses floating-point numbers by default whenever you write a number with a decimal in it.

The surprising part is that 0.1 and 0.2 are about as simple as decimal numbers get, yet adding them produces something that isn't quite 0.3. This isn't a language-specific quirk. Try it in JavaScript:

> 0.1 + 0.2
0.30000000000000004

Same result. Try it in C, Java, or Swift — same result, give or take a digit or two in how it's displayed. This tells you something important right away: whatever is going on, it isn't a bug in Python or a bug in JavaScript. It's baked into how nearly all modern hardware stores fractional numbers, following a shared standard called IEEE 754 (you'll meet it in detail in Section 3).

About This Book

If you've ever typed 0.1 + 0.2 into a Python or JavaScript console and stared confused at 0.30000000000000004, this book is for you. It's built for CS1 students hitting floating point for the first time, self-taught programmers debugging a weird rounding glitch at 2 a.m., and anyone reviewing for a computer architecture or numerical methods exam who needs the concept to finally click.

This is a computer science floating point primer that answers why is 0.1 plus 0.2 not 0.3 with real bits, not hand-waving. You'll get IEEE 754 floating point explained from the ground up, a walkthrough of how computers store decimal numbers in binary fractions, and floating point error explained simply enough to actually stick — including machine epsilon, error accumulation, and a real floating point bug in code explained line by line. It's a concise floating point arithmetic study guide: short by design, no filler.

Read it straight through, work the examples by hand, then try the problem set at the end to check what actually landed.

Keep reading

You've read the first half of Chapter 1. The complete book covers 6 chapters — readable in one sitting.

Coming soon to Amazon