From 87ac09daa88c1df338701f2d2b30b09e812cf757 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Wed, 25 May 2011 08:41:45 +0200 Subject: Simplify the use of custom scalar types, the rule is to never directly call a standard math function using std:: but rather put a using std::foo before and simply call foo: using std::max; max(a,b); --- Eigen/src/Core/MathFunctions.h | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) (limited to 'Eigen/src/Core/MathFunctions.h') diff --git a/Eigen/src/Core/MathFunctions.h b/Eigen/src/Core/MathFunctions.h index 2760e67b1..c80d30e35 100644 --- a/Eigen/src/Core/MathFunctions.h +++ b/Eigen/src/Core/MathFunctions.h @@ -87,7 +87,8 @@ struct real_impl > { static inline RealScalar run(const std::complex& x) { - return std::real(x); + using std::real; + return real(x); } }; @@ -122,7 +123,8 @@ struct imag_impl > { static inline RealScalar run(const std::complex& x) { - return std::imag(x); + using std::imag; + return imag(x); } }; @@ -244,7 +246,8 @@ struct conj_impl > { static inline std::complex run(const std::complex& x) { - return std::conj(x); + using std::conj; + return conj(x); } }; @@ -270,7 +273,8 @@ struct abs_impl typedef typename NumTraits::Real RealScalar; static inline RealScalar run(const Scalar& x) { - return std::abs(x); + using std::abs; + return abs(x); } }; @@ -305,7 +309,8 @@ struct abs2_impl > { static inline RealScalar run(const std::complex& x) { - return std::norm(x); + using std::norm; + return norm(x); } }; @@ -369,10 +374,12 @@ struct hypot_impl typedef typename NumTraits::Real RealScalar; static inline RealScalar run(const Scalar& x, const Scalar& y) { + using std::max; + using std::min; RealScalar _x = abs(x); RealScalar _y = abs(y); - RealScalar p = std::max(_x, _y); - RealScalar q = std::min(_x, _y); + RealScalar p = max(_x, _y); + RealScalar q = min(_x, _y); RealScalar qp = q/p; return p * sqrt(RealScalar(1) + qp*qp); } @@ -420,7 +427,8 @@ struct sqrt_default_impl { static inline Scalar run(const Scalar& x) { - return std::sqrt(x); + using std::sqrt; + return sqrt(x); } }; @@ -460,7 +468,7 @@ inline EIGEN_MATHFUNC_RETVAL(sqrt, Scalar) sqrt(const Scalar& x) // This macro instanciate all the necessary template mechanism which is common to all unary real functions. #define EIGEN_MATHFUNC_STANDARD_REAL_UNARY(NAME) \ template struct NAME##_default_impl { \ - static inline Scalar run(const Scalar& x) { return std::NAME(x); } \ + static inline Scalar run(const Scalar& x) { using std::NAME; return NAME(x); } \ }; \ template struct NAME##_default_impl { \ static inline Scalar run(const Scalar&) { \ @@ -495,7 +503,8 @@ struct atan2_default_impl typedef Scalar retval; static inline Scalar run(const Scalar& x, const Scalar& y) { - return std::atan2(x, y); + using std::atan2; + return atan2(x, y); } }; @@ -534,7 +543,8 @@ struct pow_default_impl typedef Scalar retval; static inline Scalar run(const Scalar& x, const Scalar& y) { - return std::pow(x, y); + using std::pow; + return pow(x, y); } }; @@ -726,7 +736,8 @@ struct scalar_fuzzy_default_impl } static inline bool isApprox(const Scalar& x, const Scalar& y, const RealScalar& prec) { - return abs(x - y) <= std::min(abs(x), abs(y)) * prec; + using std::min; + return abs(x - y) <= min(abs(x), abs(y)) * prec; } static inline bool isApproxOrLessThan(const Scalar& x, const Scalar& y, const RealScalar& prec) { @@ -764,7 +775,8 @@ struct scalar_fuzzy_default_impl } static inline bool isApprox(const Scalar& x, const Scalar& y, const RealScalar& prec) { - return abs2(x - y) <= std::min(abs2(x), abs2(y)) * prec * prec; + using std::min; + return abs2(x - y) <= min(abs2(x), abs2(y)) * prec * prec; } }; -- cgit v1.2.3