Description
[f32|f64]::EPSILON
are the machine epsilon of the type, or (as stated in the Rust docs), the distance between 1.0
and the next representable floating point number.
The page linked in the more info specifically says that abs( a - b ) < epsilon
is wrong for any value of espilon
. However, it's especially egregious with f__::EPSILON
, because for floating point numbers outside the range -2..=2
, floating point numbers cannot be f__::EPSILON
close, so abs( a - b ) < f__::EPSILON
is actually equivalent to a strict equality check.
There isn't a generally applicable solution to recommend. The most thorough resource I've found suggests comparison in ULPs for testing against a non-zero number, and testing against a fixed epsilon (but one bigger than f__::EPSILON
.
At the least, we (and probably std) shouldn't be recommending comparing against f__::EPSILON
, as it's basically as poor as bitwise equality and gives a false sense of handling the problem, when it isn't really handled.