6 #ifndef VNIX_RAT_COMMON_DENOM_HPP 7 #define VNIX_RAT_COMMON_DENOM_HPP 9 #include <vnix/gcd.hpp> 10 #include <vnix/int-types.hpp> 16 template <
unsigned NB,
unsigned DB>
class rational;
19 template <
unsigned NB1,
unsigned DB1,
unsigned NB2,
unsigned DB2>
20 struct common_denom_params;
33 template <
unsigned NB1,
unsigned DB1,
unsigned NB2,
unsigned DB2>
34 constexpr common_denom_params<NB1, DB1, NB2, DB2>
36 using cdp = common_denom_params<NB1, DB1, NB2, DB2>;
39 using gcd_t = gcd_promoted<UF1, UF2>;
40 gcd_t
const g = gcd(r1.d(), r2.d());
41 UF1
const d1g = r1.d() / g;
42 UF2
const d2g = r2.d() / g;
43 return cdp(d1g * r2.d(), r1.n() * d2g, r2.n() * d1g);
56 template <
unsigned NB1,
unsigned DB1,
unsigned NB2,
unsigned DB2>
57 struct common_denom_params {
61 constexpr static unsigned clamp64(
unsigned n) {
return n > 64 ? 64 : n; }
constexpr common_denom_params< NB1, DB1, NB2, DB2 > common_denom(rational< NB1, DB1 > r1, rational< NB2, DB2 > r2)
Compute least common denominator and corresponding numerators for the comparison of a pair of rationa...
For use by client for storage of sum of numerators.
constexpr common_denom_params(lcd_t ll, n1_t nn1, n2_t nn2)
Construct from list of initializers.
Smallest integer types for holding certain number of bits.
static constexpr unsigned clamp64(unsigned n)
Clamp an unsigned number at the maximum value of 64.
friend std::ostream & operator<<(std::ostream &s, basic_dim d)
Print to to output stream.
For storage of first numerator.
n1_t const n1
First numerator.
n2_t const n2
Second numerator.
For storage of second numerator.
Thomas E. Vaughan's public software.
Model of a fixed-precision rational number.
Classes and functions supporting a model of a fixed-precision rational number.