units
Use physical dimensions at compile-time or run-time.
Public Types | Static Public Member Functions | Public Attributes | Private Types | Private Member Functions | Friends | List of all members
vnix::rat::common_denom_params< NB1, DB1, NB2, DB2 > Struct Template Reference

Least common denominator (LCD) and corresponding numerators for the comparison of a pair of rational numbers. More...

#include <common-denom.hpp>

Public Types

enum  { LCD_BITS = clamp64(DB1 + DB2), N1_BITS = clamp64(NB1 + DB2), N2_BITS = clamp64(NB2 + DB1), NMR_BITS = (N1_BITS > N2_BITS ? N1_BITS : N2_BITS) }
 Number of bits required for storage of various items. More...
 
using lcd_t = typename int_types< LCD_BITS >::UF
 Type of LCD. More...
 
using n1_t = typename int_types< N1_BITS >::SF
 Type of first numerator. More...
 
using n2_t = typename int_types< N2_BITS >::SF
 Type of secnd numerator. More...
 

Static Public Member Functions

static constexpr unsigned clamp64 (unsigned n)
 Clamp an unsigned number at the maximum value of 64. More...
 

Public Attributes

lcd_t const lcd
 LCD. More...
 
n1_t const n1
 First numerator. More...
 
n2_t const n2
 Second numerator. More...
 

Private Types

using rat1 = rational< NB1, DB1 >
 Type of first rational. More...
 
using rat2 = rational< NB2, DB2 >
 Type of second rational. More...
 

Private Member Functions

constexpr common_denom_params (lcd_t ll, n1_t nn1, n2_t nn2)
 Construct from list of initializers. More...
 

Friends

constexpr friend common_denom_params common_denom (rat1 r1, rat2 r2)
 Allow common_denom() to call private constructor. More...
 

Detailed Description

template<unsigned NB1, unsigned DB1, unsigned NB2, unsigned DB2>
struct vnix::rat::common_denom_params< NB1, DB1, NB2, DB2 >

Least common denominator (LCD) and corresponding numerators for the comparison of a pair of rational numbers.

An instance of common_denom_params is returned by common_denom().

Template Parameters
NB1Number of bits for numerator of first rational.
DB1Number of bits for denominator of first rational.
NB2Number of bits for numerator of second rational.
DB2Number of bits for denominator of second rational.

Definition at line 20 of file common-denom.hpp.

Member Typedef Documentation

template<unsigned NB1, unsigned DB1, unsigned NB2, unsigned DB2>
using vnix::rat::common_denom_params< NB1, DB1, NB2, DB2 >::lcd_t = typename int_types<LCD_BITS>::UF

Type of LCD.

Definition at line 72 of file common-denom.hpp.

template<unsigned NB1, unsigned DB1, unsigned NB2, unsigned DB2>
using vnix::rat::common_denom_params< NB1, DB1, NB2, DB2 >::n1_t = typename int_types<N1_BITS>::SF

Type of first numerator.

Definition at line 73 of file common-denom.hpp.

template<unsigned NB1, unsigned DB1, unsigned NB2, unsigned DB2>
using vnix::rat::common_denom_params< NB1, DB1, NB2, DB2 >::n2_t = typename int_types<N2_BITS>::SF

Type of secnd numerator.

Definition at line 74 of file common-denom.hpp.

template<unsigned NB1, unsigned DB1, unsigned NB2, unsigned DB2>
using vnix::rat::common_denom_params< NB1, DB1, NB2, DB2 >::rat1 = rational<NB1, DB1>
private

Type of first rational.

Definition at line 81 of file common-denom.hpp.

template<unsigned NB1, unsigned DB1, unsigned NB2, unsigned DB2>
using vnix::rat::common_denom_params< NB1, DB1, NB2, DB2 >::rat2 = rational<NB2, DB2>
private

Type of second rational.

Definition at line 82 of file common-denom.hpp.

Member Enumeration Documentation

template<unsigned NB1, unsigned DB1, unsigned NB2, unsigned DB2>
anonymous enum

Number of bits required for storage of various items.

Enumerator
LCD_BITS 

For storage of LCD.

N1_BITS 

For storage of first numerator.

N2_BITS 

For storage of second numerator.

NMR_BITS 

For use by client for storage of sum of numerators.

Definition at line 64 of file common-denom.hpp.

64  {
65  LCD_BITS = clamp64(DB1 + DB2),
66  N1_BITS = clamp64(NB1 + DB2),
67  N2_BITS = clamp64(NB2 + DB1),
70  };
For use by client for storage of sum of numerators.
static constexpr unsigned clamp64(unsigned n)
Clamp an unsigned number at the maximum value of 64.
For storage of first numerator.
For storage of second numerator.

Constructor & Destructor Documentation

template<unsigned NB1, unsigned DB1, unsigned NB2, unsigned DB2>
constexpr vnix::rat::common_denom_params< NB1, DB1, NB2, DB2 >::common_denom_params ( lcd_t  ll,
n1_t  nn1,
n2_t  nn2 
)
inlineprivate

Construct from list of initializers.

Parameters
llLeast common denominator.
nn1First numerator.
nn2Second numerator.

Definition at line 92 of file common-denom.hpp.

93  : lcd(ll), n1(nn1), n2(nn2) {}
n1_t const n1
First numerator.
n2_t const n2
Second numerator.

Member Function Documentation

template<unsigned NB1, unsigned DB1, unsigned NB2, unsigned DB2>
static constexpr unsigned vnix::rat::common_denom_params< NB1, DB1, NB2, DB2 >::clamp64 ( unsigned  n)
inlinestatic

Clamp an unsigned number at the maximum value of 64.

Parameters
nUnsigned input.
Returns
Clamped output.

Definition at line 61 of file common-denom.hpp.

61 { return n > 64 ? 64 : n; }

Friends And Related Function Documentation

template<unsigned NB1, unsigned DB1, unsigned NB2, unsigned DB2>
constexpr friend common_denom_params common_denom ( rat1  r1,
rat2  r2 
)
friend

Allow common_denom() to call private constructor.

Template Parameters
NB1Number of bits for numerator of first rational.
DB1Number of bits for denominator of first rational.
NB2Number of bits for numerator of second rational.
DB2Number of bits for denominator of second rational.
Parameters
r1First input rational number.
r2Second input rational number.
Returns
Instance of common_denom_pairs.

Definition at line 35 of file common-denom.hpp.

35  {
36  using cdp = common_denom_params<NB1, DB1, NB2, DB2>;
37  using UF1 = typename int_types<DB1>::UF;
38  using UF2 = typename int_types<DB2>::UF;
39  using gcd_t = gcd_promoted<UF1, UF2>;
40  gcd_t const g = gcd(r1.d(), r2.d()); // GCD of input denominators.
41  UF1 const d1g = r1.d() / g; // First input denominator divided by g.
42  UF2 const d2g = r2.d() / g; // Second input denominator divided by g.
43  return cdp(d1g * r2.d(), r1.n() * d2g, r2.n() * d1g);
44 };
typename int_types< NB+1 >::UF UF
Fastest unsigned integer.
Definition: int-types.hpp:25
constexpr gcd_promoted< A, B > gcd(A a, B b)
Greatest common divisor of two numbers; only absolute values are used.
Definition: gcd.hpp:40
constexpr auto g
Constant-expression symbol for g.
Definition: units.hpp:1759

Member Data Documentation

template<unsigned NB1, unsigned DB1, unsigned NB2, unsigned DB2>
lcd_t const vnix::rat::common_denom_params< NB1, DB1, NB2, DB2 >::lcd

LCD.

Definition at line 76 of file common-denom.hpp.

template<unsigned NB1, unsigned DB1, unsigned NB2, unsigned DB2>
n1_t const vnix::rat::common_denom_params< NB1, DB1, NB2, DB2 >::n1

First numerator.

Definition at line 77 of file common-denom.hpp.

template<unsigned NB1, unsigned DB1, unsigned NB2, unsigned DB2>
n2_t const vnix::rat::common_denom_params< NB1, DB1, NB2, DB2 >::n2

Second numerator.

Definition at line 78 of file common-denom.hpp.


The documentation for this struct was generated from the following file: