5 Quantities and units library [quantities]

5.3 Utilities [qty.utils]

5.3.2 Ratio [qty.ratio]

namespace mp_units { struct ratio { // exposition only std::intmax_t num; std::intmax_t den; consteval ratio(std::intmax_t n, std::intmax_t d = 1); friend consteval bool operator==(ratio, ratio) = default; friend consteval auto operator<=>(ratio lhs, ratio rhs) { return (lhs - rhs).num <=> 0; } friend consteval ratio operator-(ratio r) { return {-r.num, r.den}; } friend consteval ratio operator+(ratio lhs, ratio rhs) { return {lhs.num * rhs.den + lhs.den * rhs.num, lhs.den * rhs.den}; } friend consteval ratio operator-(ratio lhs, ratio rhs) { return lhs + (-rhs); } friend consteval ratio operator*(ratio lhs, ratio rhs); friend consteval ratio operator/(ratio lhs, ratio rhs) { return lhs * ratio{rhs.den, rhs.num}; } }; consteval bool is-integral(ratio r) { return r.num % r.den == 0; } consteval ratio common-ratio(ratio r1, ratio r2); }
ratio represents the rational number .
Unless otherwise specified, in the following descriptions, let R(r) be std​::​ratio<N, D>, where N and D are the values of r.num and r.den.
consteval ratio(std::intmax_t n, std::intmax_t d = 1);
Let N and D be the values of n and d.
Let R be std​::​ratio<N, D>.
Effects: Equivalent to R.
Postconditions: num == R​::​num && den == R​::​den is true.
friend consteval ratio operator*(ratio lhs, ratio rhs);
Let Res be std​::​ratio_multiply<R(lhs), R(rhs)>.
Effects: Equivalent to: return {Res​::​num, Res​::​den};
consteval ratio common-ratio(ratio r1, ratio r2);
Let Res be equal to std::common_type<std::chrono::duration<int, R(r1)>, std::chrono::duration<int, R(r2)>>::type::period
Effects: Equivalent to: return {Res​::​num, Res​::​den};