diff options
Diffstat (limited to 'boost/geometry/util/math.hpp')
-rw-r--r-- | boost/geometry/util/math.hpp | 56 |
1 files changed, 55 insertions, 1 deletions
diff --git a/boost/geometry/util/math.hpp b/boost/geometry/util/math.hpp index edfa961b15..95cbdf2ce4 100644 --- a/boost/geometry/util/math.hpp +++ b/boost/geometry/util/math.hpp @@ -44,11 +44,43 @@ 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); + } +}; + +template <typename Type, bool IsFloatingPoint> +struct smaller +{ + static inline bool apply(Type const& a, Type const& b) + { + return a < b; + } +}; + +template <typename Type> +struct smaller<Type, true> +{ + static inline bool apply(Type const& a, Type const& b) + { + if (equals<Type, true>::apply(a, b)) + { + return false; + } + return a < b; } }; @@ -116,6 +148,28 @@ inline bool equals_with_epsilon(T1 const& a, T2 const& b) >::apply(a, b); } +template <typename T1, typename T2> +inline bool smaller(T1 const& a, T2 const& b) +{ + typedef typename select_most_precise<T1, T2>::type select_type; + return detail::smaller + < + select_type, + boost::is_floating_point<select_type>::type::value + >::apply(a, b); +} + +template <typename T1, typename T2> +inline bool larger(T1 const& a, T2 const& b) +{ + typedef typename select_most_precise<T1, T2>::type select_type; + return detail::smaller + < + select_type, + boost::is_floating_point<select_type>::type::value + >::apply(b, a); +} + double const d2r = geometry::math::pi<double>() / 180.0; |