
Why Every Computer Gets This Wrong - Floats Gone Wild!
https://www.youtube.com/watch?v=MFq97zUZvTs Every programmer hits it eventually. You type 0.1 + 0.2 and get 0.30000000000000004 . Not 0.3 . Not in Python, not in JavaScript, not in any language. This isn't a bug — it's IEEE 754 working exactly as designed. Why 0.1 Can't Be Stored Exactly You already know that 1/3 in decimal is 0.333... — it repeats forever. Binary has the same problem, just with different numbers. In base 2, you can only represent fractions built from powers of two: 1/2, 1/4, 1/8. But 1/10? Its denominator has a factor of 5, and binary can't express 5. So 0.1 in binary becomes 0.000110011001100110011... — repeating forever. The computer has to stop somewhere, and the stored value is 0.1000000000000000055511151231257827021181583404541015625. Close. Not exact. How IEEE 754 Stores Numbers The standard uses 64 bits split into three parts: 1 bit for the sign (positive or negative) 11 bits for the exponent (the scale — which power-of-two window) 52 bits for the mantissa (whe
Continue reading on Dev.to
Opens in a new tab


