When small rounding errors are acceptable, how should two floating point results be compared?

Check they are close, for example with Python's math.isclose().

Start playing free

  1. Check they are within a small tolerance ✔
  2. Truncate both values to whole numbers
  3. Use == like whole numbers

Why: Binary floating point carries rounding errors, so exact equality can fail for intended matches. A relative or absolute tolerance, such as Python's math.isclose(), tests whether the difference is acceptable for the task.

Huh, didn't know that: Python's default math.isclose() comparison returns true for 0.1 + 0.1 + 0.1 and 0.3.

The dad joke
Two floats walked into a bar. The bartender said, close enough.
Like this card?
Play the game

References

Answer: Check they are within a small tolerance. Binary floating point carries rounding errors, so exact equality can fail for intended matches. A relative or absolute tolerance, such as Python's math.isclose(), tests whether the difference is acceptable for the task.

  1. Python docs: Floating-Point Arithmetic, Issues and Limitations docs.python.org/3/tutorial/floatingpoint.html
    the math.isclose() function can be useful for comparing inexact values
    Checked 2026-10-10.

Think this answer is wrong? Tap "Challenge this answer" on the card in the game and tell us why.

Test yourself in the game