Add missing operators

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2013-07-16 17:20:24 -07:00
parent 5c76cac9b1
commit e7bfd9a77d
2 changed files with 7 additions and 2 deletions

View file

@ -34,7 +34,7 @@ mpz floor(mpq const & a) {
mpz r; mpz r;
mpz_tdiv_q(mpq::zval(r), mpq_numref(a.m_val), mpq_denref(a.m_val)); mpz_tdiv_q(mpq::zval(r), mpq_numref(a.m_val), mpq_denref(a.m_val));
if (a.is_neg()) if (a.is_neg())
r -= 1; --r;
return r; return r;
} }
@ -44,7 +44,7 @@ mpz ceil(mpq const & a) {
mpz r; mpz r;
mpz_tdiv_q(mpq::zval(r), mpq_numref(a.m_val), mpq_denref(a.m_val)); mpz_tdiv_q(mpq::zval(r), mpq_numref(a.m_val), mpq_denref(a.m_val));
if (a.is_pos()) if (a.is_pos())
r += 1; ++r;
return r; return r;
} }

View file

@ -79,6 +79,11 @@ public:
DEFINE_ARITH_OPS(mpz) DEFINE_ARITH_OPS(mpz)
friend mpz operator%(mpz const & a, mpz const & b); friend mpz operator%(mpz const & a, mpz const & b);
mpz & operator++() { return operator+=(1); }
mpz & operator--() { return operator-=(1); }
mpz operator++(int) { mpz r(*this); ++(*this); return r; }
mpz operator--(int) { mpz r(*this); --(*this); return r; }
mpz & operator&=(mpz const & o) { mpz_and(m_val, m_val, o.m_val); return *this; } mpz & operator&=(mpz const & o) { mpz_and(m_val, m_val, o.m_val); return *this; }
mpz & operator|=(mpz const & o) { mpz_ior(m_val, m_val, o.m_val); return *this; } mpz & operator|=(mpz const & o) { mpz_ior(m_val, m_val, o.m_val); return *this; }
mpz & operator^=(mpz const & o) { mpz_xor(m_val, m_val, o.m_val); return *this; } mpz & operator^=(mpz const & o) { mpz_xor(m_val, m_val, o.m_val); return *this; }