Uni20
Asynchronous tensor and runtime library.
Loading...
Searching...
No Matches
Public Member Functions | Friends | List of all members
uni20::exact_rational Class Reference

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.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ exact_rational() [1/6]

uni20::exact_rational::exact_rational ( )
inline

◆ exact_rational() [2/6]

uni20::exact_rational::exact_rational ( std::string_view  text)
inlineexplicit

◆ exact_rational() [3/6]

uni20::exact_rational::exact_rational ( decimal_literal  literal)
inline

◆ exact_rational() [4/6]

template<std::integral I>
requires (!std::same_as<I, bool>)
uni20::exact_rational::exact_rational ( I  value)
inline

◆ exact_rational() [5/6]

uni20::exact_rational::exact_rational ( exact_rational const &  other)
inline

◆ exact_rational() [6/6]

uni20::exact_rational::exact_rational ( exact_rational &&  other)
inlinenoexcept

Transfer the payload without allocating, leaving the source unset.

◆ ~exact_rational()

uni20::exact_rational::~exact_rational ( )
inline

Member Function Documentation

◆ at()

mpreal uni20::exact_rational::at ( Precision  precision) const
inline

Convert to a real value with one rounding at explicit precision.

◆ initialized()

constexpr bool uni20::exact_rational::initialized ( ) const
inlineconstexprnoexcept

Whether this object owns a rational value rather than being unset.

◆ is_exact()

constexpr bool uni20::exact_rational::is_exact ( ) const
inlineconstexprnoexcept

Whether this object carries an exact value; false when unset.

◆ native_handle()

mpq_srcptr uni20::exact_rational::native_handle ( ) const
inline

Borrow the read-only GMP rational while this object retains its payload.

Exceptions
std::logic_errorIf this object is unset.

◆ operator=()

exact_rational & uni20::exact_rational::operator= ( exact_rational  other)
inlinenoexcept

◆ swap()

void uni20::exact_rational::swap ( exact_rational &  other)
inlinenoexcept

Exchange payload ownership, including unset states, without allocating.

◆ to_string()

std::string uni20::exact_rational::to_string ( ) const
inline

Return the canonical numerator/denominator, or an integer when exact.

Friends And Related Symbol Documentation

◆ operator*

exact_rational operator* ( exact_rational const &  a,
exact_rational const &  b 
)
friend

◆ operator+

exact_rational operator+ ( exact_rational const &  a,
exact_rational const &  b 
)
friend

◆ operator- [1/2]

exact_rational operator- ( exact_rational const &  a)
friend

◆ operator- [2/2]

exact_rational operator- ( exact_rational const &  a,
exact_rational const &  b 
)
friend

◆ operator/

exact_rational operator/ ( exact_rational const &  a,
exact_rational const &  b 
)
friend

◆ rational_root

std::optional< exact_rational > rational_root ( exact_rational const &  x,
unsigned long  degree 
)
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.


The documentation for this class was generated from the following files: