From bcf15fb3ff5ec39f50187c157cf1f36daecb4763 Mon Sep 17 00:00:00 2001 From: Tim King Date: Sun, 6 Jun 2010 16:25:19 +0000 Subject: [PATCH] Adding += and *= to Rational. --- src/util/rational.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/util/rational.h b/src/util/rational.h index 5e187de7f..81e0f7fbd 100644 --- a/src/util/rational.h +++ b/src/util/rational.h @@ -203,10 +203,11 @@ public: } + + Rational operator+(const Rational& y) const{ return Rational( d_value + y.d_value ); } - Rational operator-(const Rational& y) const { return Rational( d_value - y.d_value ); } @@ -218,6 +219,16 @@ public: return Rational( d_value / y.d_value ); } + Rational& operator+=(const Rational& y){ + d_value += y.d_value; + return (*this); + } + + Rational& operator*=(const Rational& y){ + d_value *= y.d_value; + return (*this); + } + /** Returns a string representing the rational in the given base. */ std::string toString(int base = 10) const { return d_value.get_str(base); -- 2.30.2