[geometry] fix in comparing doubles (comparing e.g. 0 with 4e-19)

[SVN r77284]
This commit is contained in:
Barend Gehrels
2012-03-09 13:31:44 +00:00
parent 7f26c674df
commit 0c66579409

View File

@@ -44,11 +44,21 @@ struct equals
template <typename Type>
struct equals<Type, true>
{
static inline Type get_max(Type const& a, Type const& b, Type const& c)
{
return (std::max)((std::max)(a, b), c);
}
static inline bool apply(Type const& a, Type const& b)
{
if (a == b)
{
return true;
}
// See http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.17,
// FUTURE: replace by some boost tool or boost::test::close_at_tolerance
return std::abs(a - b) <= std::numeric_limits<Type>::epsilon() * std::abs(a);
return std::abs(a - b) <= std::numeric_limits<Type>::epsilon() * get_max(std::abs(a), std::abs(b), 1.0);
}
};