[math] Fix equals() for INF and -INF.

This commit is contained in:
Adam Wulkiewicz 2015-05-24 14:26:53 +02:00
parent b9ee6f0d51
commit 1bff0ad9e9

View File

@ -160,16 +160,17 @@ struct equals<Type, true>
return true; return true;
} }
bool const a_inf = boost::math::isinf(a); if (boost::math::isfinite(a) && boost::math::isfinite(b))
bool const b_inf = boost::math::isinf(b);
if (a_inf != b_inf)
{ {
// If a is INF and b is 0, the expression below returns true, but // If a is INF and b is e.g. 0, the expression below returns true
// the values are obviously not equal // but the values are obviously not equal, hence the condition
return false; return abs<Type>::apply(a - b)
<= std::numeric_limits<Type>::epsilon() * policy.apply(a, b);
}
else
{
return a == b;
} }
return abs<Type>::apply(a - b) <= std::numeric_limits<Type>::epsilon() * policy.apply(a, b);
} }
}; };