X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=src%2Freal.h;h=b107649a49815a262d295ecaa97f940994e68dac;hb=36b4b285d3dbdab423511e7188c37bd1d0443edb;hp=b76655884cfa90261cd414114bfb542941677bcc;hpb=35f1190c8c8036ed11180656769cf0c1cbf7c2b3;p=ipdf%2Fcode.git diff --git a/src/real.h b/src/real.h index b766558..b107649 100644 --- a/src/real.h +++ b/src/real.h @@ -11,6 +11,7 @@ #define REAL_VFPU 3 #define REAL_RATIONAL 4 #define REAL_RATIONAL_ARBINT 5 +#define REAL_MPFRCPP 6 #ifndef REAL #error "REAL was not defined!" @@ -30,6 +31,10 @@ #include "gmpint.h" #endif //REAL +#if REAL == REAL_MPFRCPP + #include +#endif //REAL + namespace IPDF { extern const char * g_real_name[]; @@ -54,7 +59,15 @@ namespace IPDF typedef Rational Real; inline float Float(const Real & r) {return (float)r.ToDouble();} inline double Double(const Real & r) {return r.ToDouble();} - + inline int64_t Int64(const Real & r) {return r.ToInt64();} + inline Rational Sqrt(const Rational & r) {return r.Sqrt();} +#elif REAL == REAL_MPFRCPP + typedef mpfr::mpreal Real; + inline double Double(const Real & r) {return r.toDouble();} + inline float Float(const Real & r) {return r.toDouble();} + inline int64_t Int64(const Real & r) {return r.toLong();} + inline Real Sqrt(const Real & r) {return mpfr::sqrt(r, mpfr::mpreal::get_default_rnd());} + inline Real Abs(const Real & r) {return mpfr::abs(r, mpfr::mpreal::get_default_rnd());} #else #error "Type of Real unspecified." #endif //REAL @@ -69,6 +82,8 @@ namespace IPDF inline double Double(double f) {return (double)f;} inline double Double(long double f) {return (double)(f);} inline double Sqrt(double f) {return sqrt(f);} + inline double Abs(double a) {return fabs(a);} + inline int64_t Int64(double a){return (int64_t)a;} inline Real Power(const Real & a, int n) { @@ -81,7 +96,6 @@ namespace IPDF r *= a; return r; } - struct Vec2 { Real x; @@ -89,6 +103,7 @@ namespace IPDF Vec2() : x(0), y(0) {} Vec2(Real _x, Real _y) : x(_x), y(_y) {} Vec2(const std::pair & p) : x(p.first), y(p.second) {} + Vec2(const std::pair & p) : x(p.first), y(p.second) {} bool operator==(const Vec2& other) const { return (x == other.x) && (y == other.y); } bool operator!=(const Vec2& other) const { return !(*this == other); }