From fdaa3f311a000aa470dde569d876b192badfb28f Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Mon, 25 Oct 2010 10:15:22 -0400 Subject: adapt mpreal to eigen3 mathfunctions system --- unsupported/Eigen/MPRealSupport | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) (limited to 'unsupported/Eigen/MPRealSupport') diff --git a/unsupported/Eigen/MPRealSupport b/unsupported/Eigen/MPRealSupport index 0d60cd99a..37e75b2c7 100644 --- a/unsupported/Eigen/MPRealSupport +++ b/unsupported/Eigen/MPRealSupport @@ -128,36 +128,29 @@ int main() return a + (b-a) * random(); } - } // end namespace internal -} - -namespace mpfr { - - namespace internal { - - inline const mpreal& conj(const mpreal& x) { return x; } - inline const mpreal& real(const mpreal& x) { return x; } - inline mpreal imag(const mpreal&) { return 0.0; } - inline mpreal abs(const mpreal& x) { return mpfr::fabs(x); } - inline mpreal abs2(const mpreal& x) { return x*x; } - inline mpreal sqrt(const mpreal& x) { return mpfr::sqrt(x); } - inline mpreal exp(const mpreal& x) { return mpfr::exp(x); } - inline mpreal log(const mpreal& x) { return mpfr::log(x); } - inline mpreal sin(const mpreal& x) { return mpfr::sin(x); } - inline mpreal cos(const mpreal& x) { return mpfr::cos(x); } - inline mpreal pow(const mpreal& x, mpreal& y) { return mpfr::pow(x, y); } - - bool isMuchSmallerThan(const mpreal& a, const mpreal& b, const mpreal& prec) + template<> struct conj_impl { inline static const mpfr::mpreal& run(const mpfr::mpreal& x) { return x; } }; + template<> struct real_impl { inline static const mpfr::mpreal& run(const mpfr::mpreal& x) { return x; } }; + template<> struct imag_impl { inline static const mpfr::mpreal run(const mpfr::mpreal&) { return mpfr::mpreal(0); } }; + template<> struct abs_impl { inline static const mpfr::mpreal run(const mpfr::mpreal& x) { return mpfr::fabs(x); } }; + template<> struct abs2_impl { inline static const mpfr::mpreal run(const mpfr::mpreal& x) { return x*x; } }; + template<> struct sqrt_impl { inline static const mpfr::mpreal run(const mpfr::mpreal& x) { return mpfr::sqrt(x); } }; + template<> struct exp_impl { inline static const mpfr::mpreal run(const mpfr::mpreal& x) { return mpfr::exp(x); } }; + template<> struct log_impl { inline static const mpfr::mpreal run(const mpfr::mpreal& x) { return mpfr::log(x); } }; + template<> struct sin_impl { inline static const mpfr::mpreal run(const mpfr::mpreal& x) { return mpfr::sin(x); } }; + template<> struct cos_impl { inline static const mpfr::mpreal run(const mpfr::mpreal& x) { return mpfr::cos(x); } }; + template<> struct pow_impl { inline static const mpfr::mpreal run(const mpfr::mpreal& x, const mpfr::mpreal& y) { return mpfr::pow(x, y); } }; + + bool isMuchSmallerThan(const mpfr::mpreal& a, const mpfr::mpreal& b, const mpfr::mpreal& prec) { return mpfr::abs(a) <= mpfr::abs(b) * prec; } - inline bool isApprox(const mpreal& a, const mpreal& b, const mpreal& prec) + inline bool isApprox(const mpfr::mpreal& a, const mpfr::mpreal& b, const mpfr::mpreal& prec) { return mpfr::abs(a - b) <= mpfr::min(mpfr::abs(a), mpfr::abs(b)) * prec; } - inline bool isApproxOrLessThan(const mpreal& a, const mpreal& b, const mpreal& prec) + inline bool isApproxOrLessThan(const mpfr::mpreal& a, const mpfr::mpreal& b, const mpfr::mpreal& prec) { return a <= b || isApprox(a, b, prec); } -- cgit v1.2.3