Switch language한국어
Back to the list

It's OK to compare floating-points for equality | Hacker News

TL;DR AI

Key summary

2 min read
  1. Hacker News commenters argued that using `f64::EPSILON` as a universal float-equality threshold is usually wrong.

  2. They noted that epsilon describes spacing near 1.0, so it does not scale well across large or small magnitudes.

  3. The discussion recommended exact equality for exact checks, and separate APIs for absolute, relative, or distance-based tolerances.

  4. This matters in assertions and computational geometry, where scale-aware error handling is essential.

Read the original