···3434### Why do other calculations like 0.1 + 0.4 work correctly?
35353636In that case, the result (0.5) *can* be represented exactly as a floating-point number,
3737-and the errors in the input numbers cancel each other out.
3737+and it's possible for rounding errors in the input numbers to cancel each other out.
3838+Even that can't necessarily be relied upon though. If for example those two numbers
3939+were stored in differently sized floating point representations first, and then added
4040+together, the rounding errors might not have offset each other perfectly.
38413942In other cases like 0.1 + 0.3, the result actually isn't *really* 0.4, but close enough that 0.4
4043is the shortest number that is closer to the result than to any other floating-point number. Many languages then display that number instead of converting the actual result back to the closest
4141-decimal fraction.4444+decimal fraction.