Add power operator to mpq

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2013-07-19 16:50:50 -07:00
parent a0908ba3c5
commit d75d6d4684
2 changed files with 9 additions and 0 deletions

View file

@ -59,6 +59,12 @@ mpz ceil(mpq const & a) {
return r;
}
void power(mpq & a, mpq const & b, unsigned k) {
mpz_pow_ui(mpq_numref(a.m_val), mpq_numref(b.m_val), k);
mpz_pow_ui(mpq_denref(a.m_val), mpq_denref(b.m_val), k);
mpq_canonicalize(a.m_val);
}
extern void display(std::ostream & out, __mpz_struct const * v);
std::ostream & operator<<(std::ostream & out, mpq const & v) {

View file

@ -194,6 +194,9 @@ public:
void ceil();
friend mpz ceil(mpq const & a);
friend void power(mpq & a, mpq const & b, unsigned k);
friend mpq power(mpq a, unsigned k) { power(a, a, k); return a; }
friend std::ostream & operator<<(std::ostream & out, mpq const & v);
friend void display_decimal(std::ostream & out, mpq const & a, unsigned prec);