Why 0.1 + 0.2 Is Not Exactly 0.3: How IEEE-754 Encodes Floats in Hardware
The familiar result 0.1 + 0.2 = 0.30000000000000004 stems from how processor arithmetic units represent real numbers, not from any compiler or language defect. Under the IEEE-754 single-precision standard, a 32-bit word is split into a sign bit, an 8-bit biased exponent with a bias of 127, and a 23-bit mantissa. Because normalized binary numbers always begin with a leading 1, that bit is omitted from storage, giving an effective 24 bits of precision. The standard also defines special patterns for zero, subnormal numbers, infinity, and NaN, which arise from underflow, overflow, division by zero, or undefined operations. The article explains that these encoding choices are what make decimal fractions like 0.1 and 0.2 inexact in binary.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in