You can use std::nextafter
with a fixed factor
of the epsilon
of a value like the following:
bool isNearlyEqual(double a, double b)
{
int factor = /* a fixed factor of epsilon */;
double min_a = a - (a - std::nextafter(a, std::numeric_limits<double>::lowest())) * factor;
double max_a = a + (std::nextafter(a, std::numeric_limits<double>::max()) - a) * factor;
return min_a <= b && max_a >= b;
}