Checking if two floating point numbers are equal Is this the best way to check if two floating point numbers are equal, or close to being equal?

template &lt;class T&gt;
bool IsEqual(T rhs, T lhs)
{
    T diff = std::abs(lhs - rhs);

    T epsilon = std::numeric_limits&lt;T&gt;::epsilon( ) * std::max(std::abs(rhs), std::abs(lhs));

    return diff &lt;= epsilon ;
}
Seems unlikely.  epsilon from std::numeric_limits is the smallest increment representable by the type (around the value 1).

You want to check for something "close to" equal, but you don't say what close to means for you. Assuming it to be a few multiples of epsilon, the following check would seem reasonable:

const int FEW = 10;
T diff = std::abs(lhs - rhs);
T epsilon = std::numeric_limits&lt;T&gt;::epsilon();

return diff &lt; (epsilon * FEW);