|
Uni20
Asynchronous tensor and runtime library.
|
Owning arbitrary-size rational with exact, eager arithmetic. More...
#include <exact_rational.hpp>
Public Member Functions | |
| mpreal | at (Precision precision) const |
| Convert to a real value with one rounding at explicit precision. | |
| exact_rational () | |
| exact_rational (decimal_literal literal) | |
| exact_rational (exact_rational &&other) noexcept | |
| Transfer the payload without allocating, leaving the source unset. | |
| exact_rational (exact_rational const &other) | |
| template<std::integral I> requires (!std::same_as<I, bool>) | |
| exact_rational (I value) | |
| exact_rational (std::string_view text) | |
| constexpr bool | initialized () const noexcept |
| Whether this object owns a rational value rather than being unset. | |
| constexpr bool | is_exact () const noexcept |
| Whether this object carries an exact value; false when unset. | |
| mpq_srcptr | native_handle () const |
| Borrow the read-only GMP rational while this object retains its payload. | |
| exact_rational & | operator= (exact_rational other) noexcept |
| void | swap (exact_rational &other) noexcept |
| Exchange payload ownership, including unset states, without allocating. | |
| std::string | to_string () const |
| Return the canonical numerator/denominator, or an integer when exact. | |
| ~exact_rational () | |
Friends | |
| exact_rational | operator* (exact_rational const &a, exact_rational const &b) |
| exact_rational | operator+ (exact_rational const &a, exact_rational const &b) |
| exact_rational | operator- (exact_rational const &a) |
| exact_rational | operator- (exact_rational const &a, exact_rational const &b) |
| exact_rational | operator/ (exact_rational const &a, exact_rational const &b) |
| std::optional< exact_rational > | rational_root (exact_rational const &, unsigned long) |
| Return a rational nth root when it exists, without choosing a precision. | |
Owning arbitrary-size rational with exact, eager arithmetic.
Prefer mpreal for general numerical code. Use this type when the value must remain rational, independent of any working precision. Text accepts finite decimals and signed integer fractions; division can produce rationals such as 1/3. Default construction produces zero; moving leaves the source unset. Copies and assignments preserve unset state, but numerical use throws.
|
inline |
|
inlineexplicit |
|
inline |
|
inline |
|
inline |
|
inlinenoexcept |
Transfer the payload without allocating, leaving the source unset.
|
inline |
Convert to a real value with one rounding at explicit precision.
|
inlineconstexprnoexcept |
Whether this object owns a rational value rather than being unset.
|
inlineconstexprnoexcept |
Whether this object carries an exact value; false when unset.
|
inline |
Borrow the read-only GMP rational while this object retains its payload.
| std::logic_error | If this object is unset. |
|
inlinenoexcept |
|
inlinenoexcept |
Exchange payload ownership, including unset states, without allocating.
|
inline |
Return the canonical numerator/denominator, or an integer when exact.
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
Return a rational nth root when it exists, without choosing a precision.
Negative inputs have a real root only for odd degrees. A missing result means that the root cannot be represented as a rational.