units
Use physical dimensions at compile-time or run-time.
|
Classes and functions supporting a model of a fixed-precision rational number. More...
Classes | |
struct | common_denom_params |
Least common denominator (LCD) and corresponding numerators for the comparison of a pair of rational numbers. More... | |
class | encoding |
Encoding of numerator and denominator into unsigned word. More... | |
class | normalized_pair |
Numerator and denominator of a rational number as separate numbers, not encoded into the same word. More... | |
class | rational |
Model of a fixed-precision rational number. More... | |
Functions | |
template<unsigned NB1, unsigned DB1, unsigned NB2, unsigned DB2> | |
constexpr bool | operator== (rational< NB1, DB1 > r1, rational< NB2, DB2 > r2) |
Compare rationals for equality. More... | |
template<unsigned NB1, unsigned DB1, unsigned NB2, unsigned DB2> | |
constexpr bool | operator!= (rational< NB1, DB1 > r1, rational< NB2, DB2 > r2) |
Compare rationals for inequality. More... | |
template<unsigned NB1, unsigned DB1, unsigned NB2, unsigned DB2> | |
constexpr bool | operator<= (rational< NB1, DB1 > r1, rational< NB2, DB2 > r2) |
Compare for less-than-or-equal ordering with another rational. More... | |
template<unsigned NB1, unsigned DB1, unsigned NB2, unsigned DB2> | |
constexpr bool | operator< (rational< NB1, DB1 > r1, rational< NB2, DB2 > r2) |
Compare for less-than ordering with another rational. More... | |
template<unsigned NB1, unsigned DB1, unsigned NB2, unsigned DB2> | |
constexpr bool | operator>= (rational< NB1, DB1 > r1, rational< NB2, DB2 > r2) |
Compare for greater-than-or-equal ordering with another rational. More... | |
template<unsigned NB1, unsigned DB1, unsigned NB2, unsigned DB2> | |
constexpr bool | operator> (rational< NB1, DB1 > r1, rational< NB2, DB2 > r2) |
Compare for greater-than ordering with another rational. More... | |
template<unsigned NB, unsigned DB> | |
constexpr auto | operator+ (rational< NB, DB > r) |
Copy rational number by way of unary operator+. More... | |
template<unsigned NB, unsigned DB> | |
constexpr auto | operator- (rational< NB, DB > r) |
Negate rational number. More... | |
template<unsigned NB1, unsigned DB1, unsigned NB2, unsigned DB2> | |
constexpr auto | operator+ (rational< NB1, DB1 > r1, rational< NB2, DB2 > r2) |
Sum of two rational numbers. More... | |
template<unsigned NB1, unsigned DB1, unsigned NB2, unsigned DB2> | |
constexpr auto | operator- (rational< NB1, DB1 > r1, rational< NB2, DB2 > r2) |
Difference between two rational numbers. More... | |
template<unsigned NB1, unsigned DB1, unsigned NB2, unsigned DB2> | |
constexpr auto | operator* (rational< NB1, DB1 > r1, rational< NB2, DB2 > r2) |
Product of two rational numbers. More... | |
template<unsigned NB1, unsigned DB1, unsigned NB2, unsigned DB2> | |
constexpr auto | operator/ (rational< NB1, DB1 > r1, rational< NB2, DB2 > r2) |
Quotient of two rational numbers. More... | |
template<unsigned NB1, unsigned DB1> | |
constexpr auto | operator/ (rational< NB1, DB1 > r1, typename rational< NB1, DB1 >::stype r2) |
Quotient of two rational numbers. More... | |
template<unsigned NB, unsigned DB> | |
std::ostream & | operator<< (std::ostream &s, rational< NB, DB > r) |
Print rational number to output-stream. More... | |
template<unsigned NB1, unsigned DB1, unsigned NB2, unsigned DB2> | |
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 rational numbers. More... | |
Classes and functions supporting a model of a fixed-precision rational number.
constexpr common_denom_params<NB1, DB1, NB2, DB2> vnix::rat::common_denom | ( | rational< NB1, DB1 > | r1, |
rational< NB2, DB2 > | r2 | ||
) |
Compute least common denominator and corresponding numerators for the comparison of a pair of rational numbers.
Allow common_denom() to call private constructor.
NB1 | Number of bits for numerator of first rational. |
DB1 | Number of bits for denominator of first rational. |
NB2 | Number of bits for numerator of second rational. |
DB2 | Number of bits for denominator of second rational. |
r1 | First input rational number. |
r2 | Second input rational number. |
Definition at line 35 of file common-denom.hpp.
constexpr bool vnix::rat::operator!= | ( | rational< NB1, DB1 > | r1, |
rational< NB2, DB2 > | r2 | ||
) |
Compare rationals for inequality.
NB1 | Number of numerator -bits in left -hand rational. |
DB1 | Number of denominator-bits in left -hand rational. |
NB2 | Number of numerator -bits in right-hand rational. |
DB2 | Number of denominator-bits in right-hand rational. |
r1 | Left -hand operand. |
r2 | Right-hand operand. |
Definition at line 141 of file rational.hpp.
constexpr auto vnix::rat::operator* | ( | rational< NB1, DB1 > | r1, |
rational< NB2, DB2 > | r2 | ||
) |
Product of two rational numbers.
NB1 | Number of numerator -bits in left -hand rational. |
DB1 | Number of denominator-bits in left -hand rational. |
NB2 | Number of numerator -bits in right-hand rational. |
DB2 | Number of denominator-bits in right-hand rational. |
r1 | Multiplicand. |
r2 | Multiplier. |
Definition at line 278 of file rational.hpp.
constexpr auto vnix::rat::operator+ | ( | rational< NB, DB > | r | ) |
Copy rational number by way of unary operator+.
NB | Number of bits for numerator. |
DB | Number of bits for denominator. |
r | Number to copy. |
Definition at line 206 of file rational.hpp.
constexpr auto vnix::rat::operator+ | ( | rational< NB1, DB1 > | r1, |
rational< NB2, DB2 > | r2 | ||
) |
Sum of two rational numbers.
NB1 | Number of numerator -bits in left -hand rational. |
DB1 | Number of denominator-bits in left -hand rational. |
NB2 | Number of numerator -bits in right-hand rational. |
DB2 | Number of denominator-bits in right-hand rational. |
r1 | Addend. |
r2 | Adder. |
Definition at line 231 of file rational.hpp.
constexpr auto vnix::rat::operator- | ( | rational< NB, DB > | r | ) |
Negate rational number.
NB | Number of bits for numerator. |
DB | Number of bits for denominator. |
r | Number to negate. |
Definition at line 217 of file rational.hpp.
constexpr auto vnix::rat::operator- | ( | rational< NB1, DB1 > | r1, |
rational< NB2, DB2 > | r2 | ||
) |
Difference between two rational numbers.
NB1 | Number of numerator -bits in left -hand rational. |
DB1 | Number of denominator-bits in left -hand rational. |
NB2 | Number of numerator -bits in right-hand rational. |
DB2 | Number of denominator-bits in right-hand rational. |
r1 | Minuend. |
r2 | Subtrahend. |
Definition at line 255 of file rational.hpp.
constexpr auto vnix::rat::operator/ | ( | rational< NB1, DB1 > | r1, |
rational< NB2, DB2 > | r2 | ||
) |
Quotient of two rational numbers.
NB1 | Number of numerator -bits in left -hand rational. |
DB1 | Number of denominator-bits in left -hand rational. |
NB2 | Number of numerator -bits in right-hand rational. |
DB2 | Number of denominator-bits in right-hand rational. |
r1 | Dividend. |
r2 | Divisor. |
Definition at line 301 of file rational.hpp.
constexpr auto vnix::rat::operator/ | ( | rational< NB1, DB1 > | r1, |
typename rational< NB1, DB1 >::stype | r2 | ||
) |
Quotient of two rational numbers.
NB1 | Number of numerator -bits in left -hand rational. |
DB1 | Number of denominator-bits in left -hand rational. |
r1 | Dividend. |
r2 | Divisor. |
Definition at line 313 of file rational.hpp.
constexpr bool vnix::rat::operator< | ( | rational< NB1, DB1 > | r1, |
rational< NB2, DB2 > | r2 | ||
) |
Compare for less-than ordering with another rational.
NB1 | Number of numerator -bits in left -hand rational. |
DB1 | Number of denominator-bits in left -hand rational. |
NB2 | Number of numerator -bits in right-hand rational. |
DB2 | Number of denominator-bits in right-hand rational. |
r1 | Left -hand operand. |
r2 | Right-hand operand. |
Definition at line 168 of file rational.hpp.
std::ostream& vnix::rat::operator<< | ( | std::ostream & | s, |
rational< NB, DB > | r | ||
) |
Print rational number to output-stream.
NB | Number of bits for numerator of rational. |
DB | Number of bits for denominator of rational. |
s | Reference to output-stream. |
r | Rational number. |
Definition at line 344 of file rational.hpp.
constexpr bool vnix::rat::operator<= | ( | rational< NB1, DB1 > | r1, |
rational< NB2, DB2 > | r2 | ||
) |
Compare for less-than-or-equal ordering with another rational.
NB1 | Number of numerator -bits in left -hand rational. |
DB1 | Number of denominator-bits in left -hand rational. |
NB2 | Number of numerator -bits in right-hand rational. |
DB2 | Number of denominator-bits in right-hand rational. |
r1 | Left -hand operand. |
r2 | Right-hand operand. |
Definition at line 154 of file rational.hpp.
constexpr bool vnix::rat::operator== | ( | rational< NB1, DB1 > | r1, |
rational< NB2, DB2 > | r2 | ||
) |
Compare rationals for equality.
NB1 | Number of numerator -bits in left -hand rational. |
DB1 | Number of denominator-bits in left -hand rational. |
NB2 | Number of numerator -bits in right-hand rational. |
DB2 | Number of denominator-bits in right-hand rational. |
r1 | Left -hand operand. |
r2 | Right-hand operand. |
Definition at line 128 of file rational.hpp.
constexpr bool vnix::rat::operator> | ( | rational< NB1, DB1 > | r1, |
rational< NB2, DB2 > | r2 | ||
) |
Compare for greater-than ordering with another rational.
NB1 | Number of numerator -bits in left -hand rational. |
DB1 | Number of denominator-bits in left -hand rational. |
NB2 | Number of numerator -bits in right-hand rational. |
DB2 | Number of denominator-bits in right-hand rational. |
r1 | Left -hand operand. |
r2 | Right-hand operand. |
Definition at line 195 of file rational.hpp.
constexpr bool vnix::rat::operator>= | ( | rational< NB1, DB1 > | r1, |
rational< NB2, DB2 > | r2 | ||
) |
Compare for greater-than-or-equal ordering with another rational.
NB1 | Number of numerator -bits in left -hand rational. |
DB1 | Number of denominator-bits in left -hand rational. |
NB2 | Number of numerator -bits in right-hand rational. |
DB2 | Number of denominator-bits in right-hand rational. |
r1 | Left -hand operand. |
r2 | Right-hand operand. |
Definition at line 182 of file rational.hpp.