From 0c665794099a289efa5fc3af3abb8e51140ee24b Mon Sep 17 00:00:00 2001 From: Barend Gehrels Date: Fri, 9 Mar 2012 13:31:44 +0000 Subject: [PATCH] [geometry] fix in comparing doubles (comparing e.g. 0 with 4e-19) [SVN r77284] --- include/boost/geometry/util/math.hpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/include/boost/geometry/util/math.hpp b/include/boost/geometry/util/math.hpp index edfa961b1..e394ac673 100644 --- a/include/boost/geometry/util/math.hpp +++ b/include/boost/geometry/util/math.hpp @@ -44,11 +44,21 @@ struct equals template struct equals { + 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::epsilon() * std::abs(a); + return std::abs(a - b) <= std::numeric_limits::epsilon() * get_max(std::abs(a), std::abs(b), 1.0); } };