Skip to content

Commit 2686536

Browse files
committed
simplify operator==() due to canonical form
1 parent ec5b857 commit 2686536

File tree

1 file changed

+2
-17
lines changed

1 file changed

+2
-17
lines changed

include/py2cpp/fractions.hpp

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,7 @@ namespace fun {
195195
* @return false
196196
*/
197197
constexpr auto operator==(const Z& other) const -> bool {
198-
if (this->_den == Z(1) || other == Z(0)) {
199-
return this->_num == other;
200-
}
201-
auto lhs{*this};
202-
auto rhs{other};
203-
std::swap(lhs._den, rhs);
204-
lhs.normalize2();
205-
return lhs._num == lhs._den * rhs;
198+
return this->_den == Z(1) && this->_num == other;
206199
}
207200

208201
/**
@@ -264,15 +257,7 @@ namespace fun {
264257
* @return false
265258
*/
266259
constexpr auto operator==(const Fraction& other) const -> bool {
267-
if (this->_den == other._den) {
268-
return this->_num == other._num;
269-
}
270-
auto lhs{*this};
271-
auto rhs{other};
272-
std::swap(lhs._den, rhs._num);
273-
lhs.normalize2();
274-
rhs.normalize2();
275-
return lhs._num * rhs._den == lhs._den * rhs._num;
260+
return this->_num == other._num && this->_den == other._den;
276261
}
277262

278263
/**

0 commit comments

Comments
 (0)