13 uint32_t AbsToUnsigned(int32_t
x) {
14 return static_cast<uint32_t
>(std::abs(
x));
19 if (den_ == that.den_) {
20 return num_ == that.num_;
21 }
else if ((num_ >= 0) != (that.num_ >= 0)) {
24 return AbsToUnsigned(num_) * that.den_ == AbsToUnsigned(that.num_) * den_;
29 return !(*
this == that);
33 if (den_ == that.den_) {
34 return num_ < that.num_;
35 }
else if ((num_ >= 0) != (that.num_ >= 0)) {
36 return num_ < that.num_;
38 return AbsToUnsigned(num_) * that.den_ < AbsToUnsigned(that.num_) * den_;
46 uint64_t gcd = std::gcd(num_, den_);
47 return ((num_ / gcd) << 32) | (den_ / gcd);
54 return Rational(-1 *
static_cast<int32_t
>(den_), std::abs(num_));
bool operator!=(const Rational &that) const
constexpr Rational(int32_t num)
bool operator<(const Rational &that) const
bool operator==(const Rational &that) const