Add power operator to numeric_traits

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2013-07-19 16:58:56 -07:00
parent d75d6d4684
commit 272089044e
4 changed files with 10 additions and 1 deletions

View file

@ -163,6 +163,7 @@ public:
mpbq operator--(int) { mpbq r(*this); --(*this); return r; }
friend void power(mpbq & a, mpbq const & b, unsigned k);
friend void _power(mpbq & a, mpbq const & b, unsigned k) { power(a, b, k); }
/**
\brief Return the magnitude of a = b/2^k.
@ -253,6 +254,8 @@ public:
static void set_rounding(bool plus_inf) {}
static void neg(mpbq & v) { v.neg(); }
static void reset(mpbq & v) { v = 0; }
// v <- v^k
static void power(mpbq & v, unsigned k) { _power(v, v, k); }
};
}

View file

@ -195,6 +195,7 @@ public:
friend mpz ceil(mpq const & a);
friend void power(mpq & a, mpq const & b, unsigned k);
friend void _power(mpq & a, mpq const & b, unsigned k) { power(a, b, k); }
friend mpq power(mpq a, unsigned k) { power(a, a, k); return a; }
friend std::ostream & operator<<(std::ostream & out, mpq const & v);
@ -222,6 +223,8 @@ public:
static void neg(mpq & v) { v.neg(); }
static void inv(mpq & v) { v.inv(); }
static void reset(mpq & v) { v = 0; }
// v <- v^k
static void power(mpq & v, unsigned k) { _power(v, v, k); }
};
}

View file

@ -202,6 +202,7 @@ public:
unsigned power_of_two_multiple() const { return mpz_scan1(m_val, 0); }
friend void power(mpz & a, mpz const & b, unsigned k) { mpz_pow_ui(a.m_val, b.m_val, k); }
friend void _power(mpz & a, mpz const & b, unsigned k) { power(a, b, k); }
friend mpz power(mpz const & a, unsigned k) { mpz r; power(r, a, k); return r; }
friend void rootrem(mpz & root, mpz & rem, mpz const & a, unsigned k) { mpz_rootrem(root.m_val, rem.m_val, a.m_val, k); }
@ -228,6 +229,8 @@ public:
static void set_rounding(bool plus_inf) {}
static void neg(mpz & v) { v.neg(); }
static void reset(mpz & v) { v = 0; }
// v <- v^k
static void power(mpz & v, unsigned k) { _power(v, v, k); }
};
}

View file

@ -26,7 +26,7 @@ public:
static void neg(double & v) { v = -v; }
static void inv(double & v) { v = 1.0/v; }
static void reset(double & v) { v = 0.0; }
// b <- b^k
// v <- v^k
static void power(double & v, unsigned k) { double_power(v, k); }
};