Add unary minus operator overloadings to mpq & mpfp

This commit is contained in:
Soonho Kong 2013-08-14 00:01:03 -07:00
parent d51e2e3a25
commit 70f383eb82
2 changed files with 4 additions and 0 deletions

View file

@ -448,6 +448,8 @@ public:
mpfp & operator--() { return operator-=(1lu); } mpfp & operator--() { return operator-=(1lu); }
mpfp operator--(int) { mpfp r(*this); --(*this); return r; } mpfp operator--(int) { mpfp r(*this); --(*this); return r; }
mpfp operator-() const { mpfp t = *this; t.neg(); return t; }
void floor() { mpfr_floor(m_val, m_val); } void floor() { mpfr_floor(m_val, m_val); }
void ceil () { mpfr_ceil (m_val, m_val); } void ceil () { mpfr_ceil (m_val, m_val); }
void round() { mpfr_round(m_val, m_val); } void round() { mpfr_round(m_val, m_val); }

View file

@ -178,6 +178,8 @@ public:
mpq & operator--() { return operator-=(1); } mpq & operator--() { return operator-=(1); }
mpq operator--(int) { mpq r(*this); --(*this); return r; } mpq operator--(int) { mpq r(*this); --(*this); return r; }
mpq operator-() const { mpq t = *this; t.neg(); return t; }
// a <- numerator(b) // a <- numerator(b)
friend void numerator(mpz & a, mpq const & b) { mpz_set(zval(a), mpq_numref(b.m_val)); } friend void numerator(mpz & a, mpq const & b) { mpz_set(zval(a), mpq_numref(b.m_val)); }
// a <- denominator(b) // a <- denominator(b)