aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen/src/Core
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2018-04-11 15:24:13 +0200
committerGravatar Gael Guennebaud <g.gael@free.fr>2018-04-11 15:24:13 +0200
commite43ca0320d58587736d8bab7c6ed7212aa6b8d9d (patch)
tree8e62324a39cf298456fe025fb3064dccaf26a1e3 /Eigen/src/Core
parentb0eda3cb9fc08d7b0bd39d99a1874b9575439e2c (diff)
bug #1520: workaround some -Wfloat-equal warnings by calling std::equal_to
Diffstat (limited to 'Eigen/src/Core')
-rw-r--r--Eigen/src/Core/MathFunctions.h6
-rw-r--r--Eigen/src/Core/arch/CUDA/Half.h4
-rwxr-xr-xEigen/src/Core/util/Meta.h20
3 files changed, 25 insertions, 5 deletions
diff --git a/Eigen/src/Core/MathFunctions.h b/Eigen/src/Core/MathFunctions.h
index 84f9d0cd5..ac1b7a6a1 100644
--- a/Eigen/src/Core/MathFunctions.h
+++ b/Eigen/src/Core/MathFunctions.h
@@ -473,11 +473,11 @@ namespace std_fallback {
EIGEN_USING_STD_MATH(exp);
Scalar u = exp(x);
- if (u == Scalar(1)) {
+ if (numext::equal_strict(u, Scalar(1))) {
return x;
}
Scalar um1 = u - RealScalar(1);
- if (um1 == Scalar(-1)) {
+ if (numext::equal_strict(um1, Scalar(-1))) {
return RealScalar(-1);
}
@@ -519,7 +519,7 @@ namespace std_fallback {
typedef typename NumTraits<Scalar>::Real RealScalar;
EIGEN_USING_STD_MATH(log);
Scalar x1p = RealScalar(1) + x;
- return ( x1p == Scalar(1) ) ? x : x * ( log(x1p) / (x1p - RealScalar(1)) );
+ return numext::equal_strict(x1p, Scalar(1)) ? x : x * ( log(x1p) / (x1p - RealScalar(1)) );
}
}
diff --git a/Eigen/src/Core/arch/CUDA/Half.h b/Eigen/src/Core/arch/CUDA/Half.h
index 2bb3d0d9b..c10550050 100644
--- a/Eigen/src/Core/arch/CUDA/Half.h
+++ b/Eigen/src/Core/arch/CUDA/Half.h
@@ -299,10 +299,10 @@ EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half& operator /= (half& a, const half& b)
return a;
}
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator == (const half& a, const half& b) {
- return float(a) == float(b);
+ return numext::equal_strict(float(a),float(b));
}
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator != (const half& a, const half& b) {
- return float(a) != float(b);
+ return numext::not_equal_strict(float(a), float(b));
}
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator < (const half& a, const half& b) {
return float(a) < float(b);
diff --git a/Eigen/src/Core/util/Meta.h b/Eigen/src/Core/util/Meta.h
index 998b8921a..e7729fdc8 100755
--- a/Eigen/src/Core/util/Meta.h
+++ b/Eigen/src/Core/util/Meta.h
@@ -543,6 +543,26 @@ T div_ceil(const T &a, const T &b)
return (a+b-1) / b;
}
+// The aim of the following functions is to bypass -Wfloat-equal warnings
+// when we really want a strict equality comparison on floating points.
+template<typename X, typename Y>
+bool equal_strict(const X& x,const Y& y) { return x == y; }
+
+template<>
+bool equal_strict(const float& x,const float& y) { return std::equal_to<float>()(x,y); }
+
+template<>
+bool equal_strict(const double& x,const double& y) { return std::equal_to<double>()(x,y); }
+
+template<typename X, typename Y>
+bool not_equal_strict(const X& x,const Y& y) { return x != y; }
+
+template<>
+bool not_equal_strict(const float& x,const float& y) { return std::not_equal_to<float>()(x,y); }
+
+template<>
+bool not_equal_strict(const double& x,const double& y) { return std::not_equal_to<double>()(x,y); }
+
} // end namespace numext
} // end namespace Eigen