I found a bug in the codebase I'm working in where they check for equality of two doubles (first, second
) using first == second
, but these 2 variables could be NaN
.
If both variables were NaN
the equality would be false
.
So my current solution is instead of
first == second
we use
(first == second || (std::isnan(first) && std::isnan(second))
Is there a simpler way to do this?