u128: Implement comparison operators in terms of one another

We can just implement the comparisons in terms of operator< and
implement inequality with the negation of operator==.
This commit is contained in:
Lioncash 2018-07-23 15:11:59 -04:00 committed by MerryMage
parent a04553eb91
commit 030820f649

View file

@ -69,15 +69,15 @@ inline bool operator<(u128 a, u128 b) {
} }
inline bool operator>(u128 a, u128 b) { inline bool operator>(u128 a, u128 b) {
return std::tie(a.upper, a.lower) > std::tie(b.upper, b.lower); return operator<(b, a);
} }
inline bool operator<=(u128 a, u128 b) { inline bool operator<=(u128 a, u128 b) {
return std::tie(a.upper, a.lower) <= std::tie(b.upper, b.lower); return !operator>(a, b);
} }
inline bool operator>=(u128 a, u128 b) { inline bool operator>=(u128 a, u128 b) {
return std::tie(a.upper, a.lower) >= std::tie(b.upper, b.lower); return !operator<(a, b);
} }
inline bool operator==(u128 a, u128 b) { inline bool operator==(u128 a, u128 b) {
@ -85,7 +85,7 @@ inline bool operator==(u128 a, u128 b) {
} }
inline bool operator!=(u128 a, u128 b) { inline bool operator!=(u128 a, u128 b) {
return std::tie(a.upper, a.lower) != std::tie(b.upper, b.lower); return !operator==(a, b);
} }
u128 operator<<(u128 operand, int amount); u128 operator<<(u128 operand, int amount);