From 6fc30684fd02e50e4e59f2a1fce19d7604a86b0f Mon Sep 17 00:00:00 2001 From: Rene Milk <rene.milk@uni-muenster.de> Date: Thu, 2 Jul 2015 15:32:31 +0200 Subject: [PATCH] [common/float_cmp] changes complex comparison mode to element-wise refs #59 and also tests float_cmp for actual floats --- dune/stuff/common/float_cmp_internal.hh | 9 ++++----- dune/stuff/test/common_float_cmp.cc | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/dune/stuff/common/float_cmp_internal.hh b/dune/stuff/common/float_cmp_internal.hh index 2c0872b74..51389a214 100644 --- a/dune/stuff/common/float_cmp_internal.hh +++ b/dune/stuff/common/float_cmp_internal.hh @@ -115,10 +115,8 @@ typename std::enable_if<std::is_arithmetic<T>::value, bool>::type cmp_gt(const T template <class T> bool cmp_gt(const std::complex<T>& xx, const std::complex<T>& yy) { - T x = std::abs(xx); - T y = std::abs(yy); - static_assert(std::is_arithmetic<T>::value, ""); - return std::greater<double>()(x, y); + using namespace std; + return cmp_gt({real(xx), real(yy)}, {imag(xx), imag(yy)}); } template <class XType, class YType> @@ -147,7 +145,8 @@ typename std::enable_if<std::is_arithmetic<T>::value, bool>::type cmp_lt(const T template <class T> bool cmp_lt(const std::complex<T>& xx, const std::complex<T>& yy) { - return std::less<T>()(std::abs(xx), std::abs(yy)); + using namespace std; + return cmp_lt({real(xx), real(yy)}, {imag(xx), imag(yy)}); } template <class XType, class YType> diff --git a/dune/stuff/test/common_float_cmp.cc b/dune/stuff/test/common_float_cmp.cc index 4c5ec13e8..bf90d0020 100644 --- a/dune/stuff/test/common_float_cmp.cc +++ b/dune/stuff/test/common_float_cmp.cc @@ -436,7 +436,7 @@ struct FloatCmpVector : public FloatCmpBase }; // struct FloatCmpVector -typedef testing::Types<double, std::complex<double> +typedef testing::Types<double, std::complex<double>, float, // , long double // <- this requires a patch in dune/common/float_cmp.cc // (bc. of std::max and 1e-6) > ScalarTypes; -- GitLab