A deep dive challenging the common wisdom that floating-point numbers should always be compared using epsilon values. Through multiple practical examples — game unit movement, slerp implementation, vector length, Gaussian elimination, ray-box intersection, and convex hull predicates — the author demonstrates that epsilon comparisons are usually the wrong solution. They introduce hidden bugs, lack transitivity, and rely on arbitrarily chosen thresholds. In most cases, exact equality checks (x == y) or restructured algorithms are safer and more correct. Epsilons are only genuinely appropriate in a narrow set of cases, such as unit testing floating-point math libraries.

29m read timeFrom lisyarus.github.io
Post cover image
Table of contents
ContentsFloating-points are not a black boxProblems with epsilonsCase in study: grid-based movementCase in study: spherical linear interpolationCase in study: computing vector lengthCase in study: solving linear systemsCase in study: ray-box intersectionCase in study: computing convex hullCase in study: sanitizing user inputCase in study: writing test casesTo epsilon or not to epsilon

Sort: