summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/catch/include/internal/catch_approx.hpp
diff options
context:
space:
mode:
author Miodrag Milanovic <mmicko@gmail.com>2017-02-05 15:45:26 +0100
committer Miodrag Milanovic <mmicko@gmail.com>2017-02-05 15:46:07 +0100
commit02c97cd0f7c4d630f1a90f9f2626746e47a28c09 (patch)
tree2b48d051a55f2b65525824546cd9fcf9e05907cf /3rdparty/catch/include/internal/catch_approx.hpp
parentd20b4ba6864b45d0c068d98d43e63c8bc5014a3b (diff)
Updated Catch to latest (nw)
Diffstat (limited to '3rdparty/catch/include/internal/catch_approx.hpp')
-rw-r--r--3rdparty/catch/include/internal/catch_approx.hpp72
1 files changed, 72 insertions, 0 deletions
diff --git a/3rdparty/catch/include/internal/catch_approx.hpp b/3rdparty/catch/include/internal/catch_approx.hpp
index f5dba61a70d..f193742763a 100644
--- a/3rdparty/catch/include/internal/catch_approx.hpp
+++ b/3rdparty/catch/include/internal/catch_approx.hpp
@@ -13,6 +13,10 @@
#include <cmath>
#include <limits>
+#if defined(CATCH_CONFIG_CPP11_TYPE_TRAITS)
+#include <type_traits>
+#endif
+
namespace Catch {
namespace Detail {
@@ -41,6 +45,53 @@ namespace Detail {
return approx;
}
+#if defined(CATCH_CONFIG_CPP11_TYPE_TRAITS)
+ template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
+ friend bool operator == ( const T& lhs, Approx const& rhs ) {
+ // Thanks to Richard Harris for his help refining this formula
+ auto lhs_v = double(lhs);
+ return fabs( lhs_v - rhs.m_value ) < rhs.m_epsilon * (rhs.m_scale + (std::max)( fabs(lhs_v), fabs(rhs.m_value) ) );
+ }
+
+ template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
+ friend bool operator == ( Approx const& lhs, const T& rhs ) {
+ return operator==( rhs, lhs );
+ }
+
+ template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
+ friend bool operator != ( T lhs, Approx const& rhs ) {
+ return !operator==( lhs, rhs );
+ }
+
+ template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
+ friend bool operator != ( Approx const& lhs, T rhs ) {
+ return !operator==( rhs, lhs );
+ }
+
+ template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
+ friend bool operator <= ( T lhs, Approx const& rhs )
+ {
+ return double(lhs) < rhs.m_value || lhs == rhs;
+ }
+
+ template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
+ friend bool operator <= ( Approx const& lhs, T rhs )
+ {
+ return lhs.m_value < double(rhs) || lhs == rhs;
+ }
+
+ template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
+ friend bool operator >= ( T lhs, Approx const& rhs )
+ {
+ return double(lhs) > rhs.m_value || lhs == rhs;
+ }
+
+ template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
+ friend bool operator >= ( Approx const& lhs, T rhs )
+ {
+ return lhs.m_value > double(rhs) || lhs == rhs;
+ }
+#else
friend bool operator == ( double lhs, Approx const& rhs ) {
// Thanks to Richard Harris for his help refining this formula
return fabs( lhs - rhs.m_value ) < rhs.m_epsilon * (rhs.m_scale + (std::max)( fabs(lhs), fabs(rhs.m_value) ) );
@@ -58,6 +109,27 @@ namespace Detail {
return !operator==( rhs, lhs );
}
+ friend bool operator <= ( double lhs, Approx const& rhs )
+ {
+ return lhs < rhs.m_value || lhs == rhs;
+ }
+
+ friend bool operator <= ( Approx const& lhs, double rhs )
+ {
+ return lhs.m_value < rhs || lhs == rhs;
+ }
+
+ friend bool operator >= ( double lhs, Approx const& rhs )
+ {
+ return lhs > rhs.m_value || lhs == rhs;
+ }
+
+ friend bool operator >= ( Approx const& lhs, double rhs )
+ {
+ return lhs.m_value > rhs || lhs == rhs;
+ }
+#endif
+
Approx& epsilon( double newEpsilon ) {
m_epsilon = newEpsilon;
return *this;