aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen/src/Core/MathFunctions.h
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2011-05-25 08:41:45 +0200
committerGravatar Gael Guennebaud <g.gael@free.fr>2011-05-25 08:41:45 +0200
commit87ac09daa88c1df338701f2d2b30b09e812cf757 (patch)
treefbd79b37052ff08feee169776761b3058057481d /Eigen/src/Core/MathFunctions.h
parent5541bcb7692088ecc671a9e0ebf8af96eaec208e (diff)
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);
Diffstat (limited to 'Eigen/src/Core/MathFunctions.h')
-rw-r--r--Eigen/src/Core/MathFunctions.h38
1 files changed, 25 insertions, 13 deletions
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<std::complex<RealScalar> >
{
static inline RealScalar run(const std::complex<RealScalar>& x)
{
- return std::real(x);
+ using std::real;
+ return real(x);
}
};
@@ -122,7 +123,8 @@ struct imag_impl<std::complex<RealScalar> >
{
static inline RealScalar run(const std::complex<RealScalar>& x)
{
- return std::imag(x);
+ using std::imag;
+ return imag(x);
}
};
@@ -244,7 +246,8 @@ struct conj_impl<std::complex<RealScalar> >
{
static inline std::complex<RealScalar> run(const std::complex<RealScalar>& x)
{
- return std::conj(x);
+ using std::conj;
+ return conj(x);
}
};
@@ -270,7 +273,8 @@ struct abs_impl
typedef typename NumTraits<Scalar>::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<std::complex<RealScalar> >
{
static inline RealScalar run(const std::complex<RealScalar>& x)
{
- return std::norm(x);
+ using std::norm;
+ return norm(x);
}
};
@@ -369,10 +374,12 @@ struct hypot_impl
typedef typename NumTraits<Scalar>::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<typename Scalar, bool IsInteger> 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<typename Scalar> struct NAME##_default_impl<Scalar, true> { \
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<Scalar, false, false>
}
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<Scalar, true, false>
}
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;
}
};