X-Git-Url: https://git.ucc.asn.au/?p=ipdf%2Fcode.git;a=blobdiff_plain;f=src%2Freal.h;h=d8033fc16cbf2896d8021568a87544c0bc3c760b;hp=4b2db1ce0259a47590420ebf172fadac52bde3b6;hb=9e1a33043e1242c4605f2a3a48bd948fc760d948;hpb=e0cd98bdff7f026b92f2c0e5b08639e08b98874e diff --git a/src/real.h b/src/real.h index 4b2db1c..d8033fc 100644 --- a/src/real.h +++ b/src/real.h @@ -54,12 +54,7 @@ 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 Rational pow(const Rational & a, const Rational & b) - { - ARBINT P(std::pow(static_cast(a.P), b.ToDouble())); - ARBINT Q(std::pow(static_cast(a.Q), b.ToDouble())); - return Rational(P,Q); - } + #else #error "Type of Real unspecified." #endif //REAL @@ -73,6 +68,19 @@ namespace IPDF inline double Double(float f) {return (double)f;} inline double Double(double f) {return (double)f;} inline double Double(long double f) {return (double)(f);} + + inline Real Power(const Real & a, int n) + { + if (n < 0) + { + return Power(Real(1)/a, -n); + } + Real r(1); + for (int i = 0; i < n; ++i) + r *= a; + return r; + } + } #endif //_REAL_H