DEV Community

Cover image for IEEE 754 Floating-Point: Why 0.1 + 0.2 != 0.3
Binary Dose
Binary Dose

Posted on Originally published at binarydose.in

IEEE 754 Floating-Point: Why 0.1 + 0.2 != 0.3

Why 0.1 + 0.2 != 0.3

Every software engineer encounters the floating-point surprise early in their career. But few understand what happens inside ALU registers.

⚡ The Repeating Binary Fraction

In decimal, numbers whose denominators have prime factors other than 2 and 5 repeat infinitely. In binary, only powers of 2 terminate cleanly!

0.1 in binary:

0.00011001100110011...₂
Enter fullscreen mode Exit fullscreen mode

Truncating this to 23 mantissa bits loses exact mathematical precision.

Explore the full hardware architecture guide on Binary Dose.

Top comments (0)