Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r72060 - in trunk/boost/geometry: extensions/contrib util
From: barend.gehrels_at_[hidden]
Date: 2011-05-21 09:51:15


Author: barendgehrels
Date: 2011-05-21 09:51:15 EDT (Sat, 21 May 2011)
New Revision: 72060
URL: http://svn.boost.org/trac/boost/changeset/72060

Log:
(Re)implemented equals_with_epsilon for ttmath
Therefore partly reverted earlier change with TypeForEpsilon
Text files modified:
   trunk/boost/geometry/extensions/contrib/ttmath_stub.hpp | 17 +++++++++++++++--
   trunk/boost/geometry/util/math.hpp | 19 ++++++-------------
   2 files changed, 21 insertions(+), 15 deletions(-)

Modified: trunk/boost/geometry/extensions/contrib/ttmath_stub.hpp
==============================================================================
--- trunk/boost/geometry/extensions/contrib/ttmath_stub.hpp (original)
+++ trunk/boost/geometry/extensions/contrib/ttmath_stub.hpp 2011-05-21 09:51:15 EDT (Sat, 21 May 2011)
@@ -152,12 +152,25 @@
 
     template <>
     struct define_pi<ttmath_big>
+ : public define_pi<ttmath::Big<1,4> >
+ {};
+
+ template <ttmath::uint Exponent, ttmath::uint Mantissa>
+ struct equals_with_epsilon<ttmath::Big<Exponent, Mantissa>, false>
     {
- static inline ttmath_big apply()
+ static inline bool apply(ttmath::Big<Exponent, Mantissa> const& a, ttmath::Big<Exponent, Mantissa> const& b)
         {
- return define_pi<ttmath::Big<1,4> >::apply();
+ // See implementation in util/math.hpp
+ // But here borrow the tolerance for double, to avoid exact comparison
+ ttmath::Big<Exponent, Mantissa> const epsilon = std::numeric_limits<double>::epsilon();
+ return ttmath::Abs(a - b) <= epsilon * ttmath::Abs(a);
         }
     };
+
+ template <>
+ struct equals_with_epsilon<ttmath_big, false>
+ : public equals_with_epsilon<ttmath::Big<1, 4>, false>
+ {};
 
 } // detail
 

Modified: trunk/boost/geometry/util/math.hpp
==============================================================================
--- trunk/boost/geometry/util/math.hpp (original)
+++ trunk/boost/geometry/util/math.hpp 2011-05-21 09:51:15 EDT (Sat, 21 May 2011)
@@ -32,7 +32,7 @@
 {
 
 
-template <typename Type, bool, typename TypeForEpsilon = Type>
+template <typename Type, bool IsFloatingPoint>
 struct equals
 {
     static inline bool apply(Type const& a, Type const& b)
@@ -41,27 +41,20 @@
     }
 };
 
-template <typename Type, typename TypeForEpsilon>
-struct equals<Type, true, TypeForEpsilon>
+template <typename Type>
+struct equals<Type, true>
 {
     static inline bool apply(Type const& a, Type const& b)
     {
         // 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
- Type const epsilon = std::numeric_limits<TypeForEpsilon>::epsilon();
- return std::abs(a - b) <= epsilon * std::abs(a);
+ return std::abs(a - b) <= std::numeric_limits<Type>::epsilon() * std::abs(a);
     }
 };
 
 
-template <typename Type, bool>
-struct equals_with_epsilon {};
-
-template <typename Type>
-struct equals_with_epsilon<Type, false> : public equals<Type, true, double> {};
-
-template <typename Type>
-struct equals_with_epsilon<Type, true> : public equals<Type, true> {};
+template <typename Type, bool IsFloatingPoint>
+struct equals_with_epsilon : public equals<Type, IsFloatingPoint> {};
 
 
 /*!


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk