u128: Add comparison operators

This commit is contained in:
MerryMage 2018-07-23 15:56:40 +01:00
parent f17cd6f2c5
commit 3e62fea003

View file

@ -7,6 +7,7 @@
#pragma once
#include <cstring>
#include <tuple>
#include <type_traits>
#include "common/bit_util.h"
@ -51,6 +52,30 @@ inline u128 operator-(u128 a, u128 b) {
return result;
}
inline bool operator<(u128 a, u128 b) {
return std::tie(a.upper, a.lower) < std::tie(b.upper, b.lower);
}
inline bool operator>(u128 a, u128 b) {
return std::tie(a.upper, a.lower) > std::tie(b.upper, b.lower);
}
inline bool operator<=(u128 a, u128 b) {
return std::tie(a.upper, a.lower) <= std::tie(b.upper, b.lower);
}
inline bool operator>=(u128 a, u128 b) {
return std::tie(a.upper, a.lower) >= std::tie(b.upper, b.lower);
}
inline bool operator==(u128 a, u128 b) {
return std::tie(a.upper, a.lower) == std::tie(b.upper, b.lower);
}
inline bool operator!=(u128 a, u128 b) {
return std::tie(a.upper, a.lower) != std::tie(b.upper, b.lower);
}
u128 operator<<(u128 operand, int amount);
u128 operator>>(u128 operand, int amount);