diff --git a/src/numerics/mpq.cpp b/src/numerics/mpq.cpp index e0d3a235c..90dad4f9a 100644 --- a/src/numerics/mpq.cpp +++ b/src/numerics/mpq.cpp @@ -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) { diff --git a/src/numerics/mpq.h b/src/numerics/mpq.h index 396e88f65..af388417a 100644 --- a/src/numerics/mpq.h +++ b/src/numerics/mpq.h @@ -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);