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...₂ Truncating this to 23 mantissa bits loses exact mathematical precision.
Explore the full hardware architecture guide on Binary Dose.
原文:https://www.a8q9.cn/en/article/ieee-754-floating-point-why-0-1-0-2-0-3-caa812.html