Why 0.1 + 0.2 Isn't 0.3 (and Why Minecraft Has the Far Lands)

How IEEE 754 packs huge ranges into fixed bits, where the dropped rounding bit comes from, and why the gap between numbers doubles every octave.

Jump to section 3 sections
  1. Fixed bits, repeating binary fractions
  2. What actually happens when you add 0.1 + 0.2
  3. Why the number line stretches out (and x + 1 === x)

Every programmer hits 0.1 + 0.2 === 0.30000000000000004 in their first month, shrugs, blames floating-point math, and moves on. What gets skipped is that the exact same design decision also explains why old versions of Minecraft shattered into jagged terrain walls if you walked millions of blocks from spawn, and why adding 1 to a large float can silently return the original number unchanged.

The whole mystery collapses down to 16 bits.

Fixed bits, repeating binary fractions

A 16-bit float (IEEE 754 binary16, the compact cousin of the 32-bit and 64-bit floats in your CPU and GPU) splits its 16 bits into three fields: 1 sign bit, 5 exponent bits that pick which power-of-two bucket you’re in, and 10 mantissa bits that place you inside that bucket.

In base 10, 1/3 never terminates (0.33333...) because 3 doesn’t divide 10. In base 2, 1/10 has the exact same problem: 0.1 in binary is 0.00011001100110011... repeating forever. Because a float only has a fixed number of mantissa bits, the hardware slices the repeating tail off and rounds to the nearest pattern that fits.

Tap any bit to flip it, or step -1/+1 ULP. Gap to next representable float16: 0.00006103515625.
Try this:

Tap 0.1 and then hit +1 ULP once: it jumps straight from 0.0999756 to 0.1000366, proving exact 0.1 sits in the void between adjacent bit patterns. Then compare 0.1 and 0.2 to see all 10 green mantissa bits stay identical while the teal exponent bumps by 1.

What actually happens when you add 0.1 + 0.2

To add two floating-point numbers, the CPU has to line up their decimal (binary) points first, just like adding 1.2 x 10^3 + 3.4 x 10^2 by hand. It shifts the smaller number’s significand to the right until both numbers share the larger exponent.

Anything pushed past the right edge of the mantissa register hits a hard precision wall. For 0.1 + 0.2, 0.1 shifts right by 1 bit, its repeating tail spills past the wall, and the final rounded sum lands just off 0.3 (0.3000488 in binary16, or 0.30000000000000004 in binary64).

Sliding 0.1 right by 1 bit aligns both exponents at 2^(-3), pushing low bits past the 10-bit wall (stored result: 0.2998047, not 0.30000000000000004).
Try this:

Select 2048 + 1 above and watch 1 slide 11 slots to the right, completely past the 10-bit wall, leaving the sum untouched at 2048.

Why the number line stretches out (and x + 1 === x)

That exponent trick lets a 16-bit number reach 65,504 while still representing numbers smaller than 0.0001. The price is uneven spacing.

Every power-of-two interval ([1, 2], [2, 4], [1024, 2048], [2048, 4096]) gets the exact same number of mantissa ticks (1,024 steps in binary16, or 8,388,608 steps in 32-bit float). Because each interval is twice as wide as the one before it, the gap between consecutive representable floats doubles every time you cross a power of two.

Between 1 and 2, the ticks sit 0.00098 apart. By 1024, those same 1,024 ticks are spaced 1.0 apart. Step past 2048, and the gap widens to 2.0, so 2048 + 1 lands in the void and rounds straight back to 2048.

At 2,048, the gap to the next float16 is 2. Adding 1 lands short of the halfway mark and snaps right back to 2,048.
Try this:

Slide from 1,024 to 2,048 and press Try +1 to feel the jump snap back into place. Then drag directly along the number line past the dotted halfway tick to watch round-to-nearest-even pull it onto the next representable float.

In 32-bit floats (f32), the exact same cliff arrives at 2^24 = 16,777,216. Past that coordinate in a game engine, you can no longer nudge a vertex by 1 unit, physics steps snap in visible chunks, and noise functions receive stair-stepped coordinates that tear smooth terrain into jagged walls. Modern engines avoid the cliff either by switching world coordinates to 64-bit doubles (2^53) or by quietly recentering the world origin around the player so you never walk far enough from 0 for the ticks to spread apart.