Field of rational numbers ℚ = { p/q : p, q ∈ ℤ, q ≠ 0 } with selectable precision.
More...
|
| | Rationals (int n=0, int d=1) |
| | Construct n / d, simplified to lowest terms with positive denominator.
|
| | Rationals (const Rationals &other)=default |
| | Rationals (Rationals &&other)=default |
| constexpr Rationals & | operator= (int l) |
| | Assign the integer l as l / 1.
|
| constexpr Rationals & | operator= (const Rationals &rhs)=default |
| Rationals & | operator= (Rationals &&rhs)=default |
| constexpr bool | operator== (const Rationals< T > &rhs) const |
| | Cross-multiplication equality.
|
| constexpr Rationals | operator- () const & |
| | Additive inverse (lvalue overload returns a copy with negated numerator).
|
| constexpr Rationals & | operator- () && |
| | Additive inverse (rvalue overload negates in place).
|
| constexpr Rationals & | operator+= (const Rationals &rhs) |
| | *this += rhs, result kept in lowest terms
|
| constexpr Rationals & | operator-= (const Rationals &rhs) |
| | *this -= rhs, result kept in lowest terms
|
| constexpr Rationals & | operator*= (const Rationals &rhs) |
| | *this *= rhs, result kept in lowest terms
|
| Rationals & | operator/= (const Rationals &rhs) |
| | *this /= rhs; throws std::invalid_argument if rhs is zero
|
| Rationals & | randomize () |
| | Random rational (bounded numerator and denominator), simplified.
|
| Rationals & | randomize_force_change () |
| | Like randomize but guaranteed to differ from the current value.
|
| size_t | get_multiplicative_order () const |
| | Multiplicative order.
|
| size_t | get_additive_order () const noexcept |
| | Additive order: 1 for zero, 0 (infinite) otherwise (characteristic 0).
|
| constexpr bool | has_positive_sign () const noexcept |
| | Sign predicate (true iff numerator and denominator share their sign).
|
| constexpr bool | is_zero () const noexcept |
| | True iff numerator is zero.
|
| constexpr Rationals & | erase () noexcept |
| | Mark this element as erased.
|
| constexpr Rationals & | unerase () noexcept |
| | Clear the erasure flag, resetting to additive identity 0/1.
|
| constexpr bool | is_erased () const noexcept |
| | Test whether this element is currently erased (encoded as denominator == 0).
|
| constexpr const T & | get_numerator () const noexcept |
| | Numerator (sign carrier).
|
| constexpr const T & | get_denominator () const noexcept |
| | Denominator (always positive after simplification).
|
| Rationals< InfInt > & | operator= (int l)=delete |
| | Assign from int — derived must implement.
|
| constexpr bool | operator!= (const Rationals< InfInt > &rhs) const |
| | Inequality, defined as !(*this == rhs).
|
| constexpr Rationals< InfInt > | operator+ () const & |
| | Unary + on an lvalue: returns a copy.
|
| Rationals< InfInt > | operator- () const &noexcept=delete |
| | Additive inverse on an lvalue — derived must implement.
|
| Rationals< InfInt > & | operator+= (const Rationals< InfInt > &rhs) noexcept=delete |
| | *this += rhs — derived must implement
|
| Rationals< InfInt > & | operator-= (const Rationals< InfInt > &rhs) noexcept=delete |
| | *this -= rhs — derived must implement
|
| Rationals< InfInt > & | operator*= (const Rationals< InfInt > &rhs) noexcept=delete |
| | *this *= rhs — derived must implement
|
| Rationals< InfInt > & | operator/= (const Rationals< InfInt > &rhs)=delete |
| | *this /= rhs; throws std::invalid_argument if rhs is zero — derived must implement
|
| Field & | randomize ()=delete |
| | Uniform random element of the field — derived must implement; may return the same value.
|
| Field & | randomize_force_change ()=delete |
| | Like randomize but guaranteed to differ from the current value — derived must implement.
|
| size_t | get_multiplicative_order () const=delete |
| | Smallest k > 0 with this^k == 1; throws std::invalid_argument if *this is zero.
|
| size_t | get_additive_order () const=delete |
| | Smallest k > 0 with k * *this == 0; for finite fields of characteristic p this is p (or 1 for zero); for ℚ it is 1 for zero and 0 (infinite) otherwise.
|
| bool | has_positive_sign () const noexcept=delete |
| | True if the element is "positive" (always true for finite fields; sign of numerator for ℚ).
|
| bool | is_zero () const noexcept=delete |
| | True if *this is the additive identity.
|
| Field & | erase () noexcept=delete |
| | Mark this element as erased (out-of-field marker for erasure decoding).
|
| Field & | unerase () noexcept=delete |
| | Clear the erasure flag, resetting to additive identity.
|
| bool | is_erased () const noexcept=delete |
| | Test whether this element is currently erased.
|
template<SignedIntType T = InfInt>
class CECCO::Rationals< T >
Field of rational numbers ℚ = { p/q : p, q ∈ ℤ, q ≠ 0 } with selectable precision.
- Template Parameters
-
Characteristic 0. Values are kept in lowest terms with positive denominator at all times, so equality is numerator_a * denominator_b == numerator_b * denominator_a. Construction with a zero denominator throws std::invalid_argument.
Pick T = InfInt for true ℚ — a fixed-width T (e.g. int, long long) caps numerator and denominator and silently overflows past that range.
Usage_Example
auto c = a + b;
auto d = a / b;
std::cout << c;
Rationals(int n=0, int d=1)
Construct n / d, simplified to lowest terms with positive denominator.
Definition at line 471 of file fields.hpp.