Skip to content
Snippets Groups Projects
Commit a7c69a6d authored by Philippe Gorley's avatar Philippe Gorley Committed by Sébastien Blin
Browse files

rational: add missing const


Change-Id: I1b7db0f3f1bf335b63488d2d3cd6d09452b0b17f
Reviewed-by: default avatarSebastien Blin <sebastien.blin@savoirfairelinux.com>
parent 6c77382c
No related branches found
No related tags found
No related merge requests found
......@@ -64,16 +64,16 @@ public:
// operators are available - see operators.hpp
// Arithmetic operators
rational operator+ (const rational& r) {
rational operator+ (const rational& r) const {
return {num_*r.den_ + r.num_*den_, den_*r.den_};
}
rational operator- (const rational& r) {
rational operator- (const rational& r) const {
return {num_*r.den_ - r.num_*den_, den_*r.den_};
}
rational operator* (const rational& r) {
rational operator* (const rational& r) const {
return {num_*r.num_, den_*r.den_};
}
rational operator/ (const rational& r) {
rational operator/ (const rational& r) const {
return {num_*r.den_, den_*r.num_};
}
......@@ -117,12 +117,18 @@ public:
bool inv = (den_ > 0) != (r.den_ > 0);
return inv != (num_ * r.den_ < den_ * r.num_);
}
bool operator> (const rational& r) const {
bool inv = (den_ > 0) != (r.den_ > 0);
return inv != (num_ * r.den_ > den_ * r.num_);
}
bool operator== (const rational& r) const { return num_ * r.den_ == den_ * r.num_; }
bool operator!= (const rational& r) const { return num_ * r.den_ != den_ * r.num_; }
// Comparison with integers
bool operator< (I i) const { return num_ < i * den_; }
bool operator> (I i) const { return num_ > i * den_; }
bool operator== (I i) const { return num_ == i * den_; }
bool operator!= (I i) const { return num_ != i * den_; }
private:
I num_ {0};
I den_ {1};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment