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

Owning exact rational or finite-precision MPFR real, with eager arithmetic. More...

#include <mpreal.hpp>

Public Member Functions

mpreal at (Precision p) const
 
void copy_to (mpfr_ptr destination) const
 Round into an initialized MPFR destination at its existing precision.
 
exact_rational const & exact_value () const
 Borrow the exact rational; valid while this object retains its state.
 
bool initialized () const noexcept
 Whether this object holds an exact or approximate numerical value.
 
bool is_exact () const noexcept
 Whether the active payload is an exact rational.
 
 mpreal ()
 Construct exact zero for ordinary generic accumulators.
 
 mpreal (decimal_literal value)
 
 mpreal (decimal_literal value, Precision p)
 
 mpreal (exact_rational const &value, Precision p)
 
 mpreal (exact_rational value)
 Retain an exact rational without rounding.
 
template<class F >
requires (std::same_as<F, float> || std::same_as<F, double> || std::same_as<F, long double>)
 mpreal (F value, Precision p)
 Import float, double or long double; precision must be finite.
 
template<std::integral I>
requires (!std::same_as<I, bool>)
 mpreal (I value)
 
template<std::integral I>
requires (!std::same_as<I, bool>)
 mpreal (I value, Precision p)
 
 mpreal (mpfr_srcptr value, Precision p)
 Copy a valid borrowed MPFR value, rounding at finite precision.
 
 mpreal (mpreal &&other) noexcept
 Transfer ownership, leaving the source unset.
 
 mpreal (mpreal const &)=default
 
 mpreal (mpreal const &other, Precision p)
 Convert to finite precision, or retain an already-exact value in exact mode.
 
 mpreal (Precision p)
 Construct zero at finite precision, or exact zero.
 
 mpreal (std::string_view text, Precision p)
 Parse a complete decimal or integer fraction at the requested precision.
 
 mpreal (uninitialized_t) noexcept
 Construct an unset placeholder for overwrite storage.
 
mpfr_srcptr native_handle () const
 Borrow an approximate MPFR value; exact and unset states require explicit materialization first.
 
 operator double () const
 
 operator float () const
 Explicitly round to a native format, nearest with ties to even.
 
 operator long double () const
 
mpreal & operator*= (exact_rational const &rhs)
 
mpreal & operator*= (mpreal const &rhs)
 
mpreal & operator+= (exact_rational const &rhs)
 
mpreal & operator+= (mpreal const &rhs)
 
mpreal & operator-= (exact_rational const &rhs)
 
mpreal & operator-= (mpreal const &rhs)
 
mpreal & operator/= (exact_rational const &rhs)
 
mpreal & operator/= (mpreal const &rhs)
 
mpreal & operator= (mpreal other) noexcept
 
Precision precision () const
 Return exact state or the working precision stored by MPFR.
 
void swap (mpreal &other) noexcept
 
std::string to_string (std::size_t digits=0) const
 Format exact rationals as numerator/denominator and approximations as decimal scientific notation.
 

Friends

mpreal epsilon (Precision precision)
 Spacing above one for a specified binary working precision.
 

Detailed Description

Owning exact rational or finite-precision MPFR real, with eager arithmetic.

Default construction is exact zero. Integers and exact literals need no working precision. Approximate arithmetic rounds to nearest, ties to even, and unequal finite precisions require explicit conversion. Assignment adopts the source state and precision. Native floating inputs require explicit finite precision.

Constructor & Destructor Documentation

◆ mpreal() [1/15]

uni20::mpreal::mpreal ( )
inline

Construct exact zero for ordinary generic accumulators.

◆ mpreal() [2/15]

uni20::mpreal::mpreal ( uninitialized_t  )
inlineexplicitnoexcept

Construct an unset placeholder for overwrite storage.

◆ mpreal() [3/15]

uni20::mpreal::mpreal ( Precision  p)
inlineexplicit

Construct zero at finite precision, or exact zero.

◆ mpreal() [4/15]

uni20::mpreal::mpreal ( exact_rational  value)
inlineexplicit

Retain an exact rational without rounding.

Exceptions
std::logic_errorIf the source is unset.

◆ mpreal() [5/15]

uni20::mpreal::mpreal ( decimal_literal  value)
inlineexplicit

◆ mpreal() [6/15]

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

◆ mpreal() [7/15]

uni20::mpreal::mpreal ( std::string_view  text,
Precision  p 
)
inline

Parse a complete decimal or integer fraction at the requested precision.

◆ mpreal() [8/15]

uni20::mpreal::mpreal ( exact_rational const &  value,
Precision  p 
)
inline

◆ mpreal() [9/15]

uni20::mpreal::mpreal ( decimal_literal  value,
Precision  p 
)
inline

◆ mpreal() [10/15]

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

◆ mpreal() [11/15]

uni20::mpreal::mpreal ( mpfr_srcptr  value,
Precision  p 
)
inlineexplicit

Copy a valid borrowed MPFR value, rounding at finite precision.

Precondition
value points to an initialized MPFR object during this call.

◆ mpreal() [12/15]

template<class F >
requires (std::same_as<F, float> || std::same_as<F, double> || std::same_as<F, long double>)
uni20::mpreal::mpreal ( F  value,
Precision  p 
)
inline

Import float, double or long double; precision must be finite.

◆ mpreal() [13/15]

uni20::mpreal::mpreal ( mpreal const &  other,
Precision  p 
)
inline

Convert to finite precision, or retain an already-exact value in exact mode.

Exceptions
std::invalid_argumentIf asked to reclassify an approximation as exact.

◆ mpreal() [14/15]

uni20::mpreal::mpreal ( mpreal const &  )
default

◆ mpreal() [15/15]

uni20::mpreal::mpreal ( mpreal &&  other)
inlinenoexcept

Transfer ownership, leaving the source unset.

Member Function Documentation

◆ at()

mpreal uni20::mpreal::at ( Precision  p) const
inline

◆ copy_to()

void uni20::mpreal::copy_to ( mpfr_ptr  destination) const
inline

Round into an initialized MPFR destination at its existing precision.

◆ exact_value()

exact_rational const & uni20::mpreal::exact_value ( ) const
inline

Borrow the exact rational; valid while this object retains its state.

◆ initialized()

bool uni20::mpreal::initialized ( ) const
inlinenoexcept

Whether this object holds an exact or approximate numerical value.

◆ is_exact()

bool uni20::mpreal::is_exact ( ) const
inlinenoexcept

Whether the active payload is an exact rational.

◆ native_handle()

mpfr_srcptr uni20::mpreal::native_handle ( ) const
inline

Borrow an approximate MPFR value; exact and unset states require explicit materialization first.

◆ operator double()

uni20::mpreal::operator double ( ) const
inlineexplicit

◆ operator float()

uni20::mpreal::operator float ( ) const
inlineexplicit

Explicitly round to a native format, nearest with ties to even.

◆ operator long double()

uni20::mpreal::operator long double ( ) const
inlineexplicit

◆ operator*=() [1/2]

mpreal & uni20::mpreal::operator*= ( exact_rational const &  rhs)
inline

◆ operator*=() [2/2]

mpreal & uni20::mpreal::operator*= ( mpreal const &  rhs)
inline

◆ operator+=() [1/2]

mpreal & uni20::mpreal::operator+= ( exact_rational const &  rhs)
inline

◆ operator+=() [2/2]

mpreal & uni20::mpreal::operator+= ( mpreal const &  rhs)
inline

◆ operator-=() [1/2]

mpreal & uni20::mpreal::operator-= ( exact_rational const &  rhs)
inline

◆ operator-=() [2/2]

mpreal & uni20::mpreal::operator-= ( mpreal const &  rhs)
inline

◆ operator/=() [1/2]

mpreal & uni20::mpreal::operator/= ( exact_rational const &  rhs)
inline

◆ operator/=() [2/2]

mpreal & uni20::mpreal::operator/= ( mpreal const &  rhs)
inline

◆ operator=()

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

◆ precision()

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

Return exact state or the working precision stored by MPFR.

◆ swap()

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

◆ to_string()

std::string uni20::mpreal::to_string ( std::size_t  digits = 0) const
inline

Format exact rationals as numerator/denominator and approximations as decimal scientific notation.

Exact values retain their rational spelling regardless of digits. For approximations, zero digits requests a round-trip representation.

Friends And Related Symbol Documentation

◆ epsilon

mpreal epsilon ( Precision  precision)
friend

Spacing above one for a specified binary working precision.


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