32-bit floats only have 24 bits of precision. Thus, a
float cannot hold b
exactly - it does the best job it can by setting some exponent and then mantissa to get as close as possible.
When you then consider the floating point representation of b
and a
, and try and add them, the addition operation will shift the small number a
's mantissa downwards as it tries to match b
's exponent, to the point where the value (3) falls off the end and you're left with 0. Hence, the addition operator ends up adding floating point zero to b
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…