Skip to main content

ExactReal

Struct ExactReal 

Source
pub struct ExactReal { /* private fields */ }
Expand description

A computable real number. See the module documentation.

Implementations§

Source§

impl ExactReal

Source

pub fn from_i64(n: i64) -> ExactReal

Source

pub fn from_rational(r: Rational) -> ExactReal

Source

pub fn from_algebraic(a: Algebraic) -> ExactReal

Source

pub fn from_f64(f: f64) -> Option<ExactReal>

The exact value of a finite float; None for NaN and the infinities.

Source

pub fn pi() -> ExactReal

Source

pub fn e() -> ExactReal

Source

pub fn exact_algebraic(&self) -> Option<Algebraic>

The value as an algebraic number, when it is one exactly.

Source

pub fn is_exactly_zero(&self) -> bool

True only when an exact form proves the value is zero.

Source

pub fn is_exact_form(&self) -> bool

Held in a form whose equality is decidable.

Source

pub fn add(&self, o: &ExactReal) -> ExactReal

Source

pub fn neg(&self) -> ExactReal

Source

pub fn sub(&self, o: &ExactReal) -> ExactReal

Source

pub fn mul(&self, o: &ExactReal) -> ExactReal

Source

pub fn recip(&self) -> Result<ExactReal, RealError>

1/self: refused when the value is exactly zero; a general value that turns out to be zero fails when it is evaluated.

Source

pub fn div(&self, o: &ExactReal) -> Result<ExactReal, RealError>

Source

pub fn pow(&self, k: i32) -> Option<ExactReal>

self^k; None only for zero to a negative power.

Source

pub fn defined( definition: Definition, name: &str, source: Arc<dyn Approximant>, ) -> ExactReal

The real number source defines (see Definition), name being how the program spells the function. Its digits or approximations are read from the function only as a refinement needs them, and each is read once.

Source

pub fn is_transmissible(&self) -> bool

Whether the number can travel as data: one built from a function a program defines cannot, its function staying with the program.

Source

pub fn flow( field: &Field, start: &[ExactReal], t: &Rational, ) -> Option<Vec<ExactReal>>

The solution of x' = f(x) from start at time t ≥ 0, one general real per component, enclosed by validated Taylor integration (crate::ode); None when the field’s shape does not match the start or the time is negative. The components share one integration.

Source

pub fn sqrt(&self) -> Result<ExactReal, RealError>

The nonnegative square root; exact where ExactReal::nth_root is.

Source

pub fn nth_root(&self, n: u32) -> Result<ExactReal, RealError>

The real n-th root (n ≥ 1), the nonnegative one for even n. Exact on algebraic numbers and on a single real exponential term, ⁿ√(c·e^β) = ⁿ√c·e^(β/n); an even root of a value held exactly as negative is refused. Any other value’s square root is evaluated as one, and its higher roots are e^(ln|x|/n) with the sign of x, which must then be told from zero.

Source

pub fn exp(&self) -> ExactReal

Source

pub fn log(&self) -> Result<ExactReal, RealError>

The natural logarithm: refused at an exactly known nonpositive value; exact on a single real exponential term with a positive algebraic coefficient (log(c·e^β) = β + log c).

Source

pub fn sin(&self) -> ExactReal

Source

pub fn cos(&self) -> ExactReal

Source

pub fn cosh(&self) -> ExactReal

Source

pub fn sinh(&self) -> ExactReal

Source

pub fn enclosure(&self, bits: u32) -> Result<(Rational, Rational), RealError>

A closed interval holding the value, at most 2^-bits wide.

Source

pub fn compare(&self, o: &ExactReal, budget: u32) -> Result<Ordering, RealError>

The order of two values. When their difference has an exact form the answer is exact (a nonzero exact difference is refined until its sign shows, which always terminates); otherwise the difference is refined to 2^-budget and the comparison fails loudly if the values have not separated.

Source

pub fn compare_within( &self, o: &ExactReal, tolerance: &Rational, ) -> Result<Closeness, RealError>

Total comparison against a tolerance: Close when the difference is certainly within tolerance, otherwise the certain side — decided from one enclosure of the difference narrower than a quarter of the tolerance. Fails only when the difference itself cannot be evaluated (a division by a quantity inseparable from zero, a logarithm of a nonpositive number).

Source

pub fn floor(&self, budget: u32) -> Result<BigInt, RealError>

⌊self⌋: exact on algebraic numbers; otherwise refined until the enclosure lies within one unit interval, failing at 2^-budget.

Source

pub fn to_decimal(&self, sig: u32) -> String

sig significant digits, correctly rounded (half away from zero on an exact tie), in plain positional notation; a value that cannot be printed shows its error in angle brackets.

Source

pub fn try_to_decimal(&self, sig: u32) -> Result<String, RealError>

ExactReal::to_decimal, with the failure (a value inseparable from zero or from a rounding boundary within the budget) returned rather than printed.

Source

pub fn truncated_decimal(&self, frac: u32) -> Result<String, RealError>

The integer part and exactly frac digits after the point, truncated toward zero.

Source

pub fn describe(&self) -> String

A structural description: exact forms symbolically, general reals as the formula that built them (π + e, log(2), 1/(π - e)), never by evaluating them.

Trait Implementations§

Source§

impl Clone for ExactReal

Source§

fn clone(&self) -> ExactReal

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ExactReal

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for ExactReal

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

An exact form symbolically (√2, e^2 + 1, cos(1), π^2 + 1); a general real as DISPLAY_DIGITS correctly rounded significant digits.

Source§

impl ExactCodec for ExactReal

Source§

fn write(&self, out: &mut Vec<u8>)

A form tag, then the form: 0 an algebraic number; 1 an exponential sum (each term’s exponent and coefficient as real and imaginary algebraic parts); 2 a polynomial in π (each power and coefficient); 3 a general real as the operation that built it (0 add, 1 multiply, 2 negate, 3 reciprocal, 4 exp, 5 log, 6 sin, 7 cos, 8 square root) and its operands.

Source§

fn read(buf: &[u8], pos: &mut usize) -> Option<Self>

Source§

fn to_bytes(&self) -> Vec<u8> ⓘ

Source§

fn from_bytes(buf: &[u8]) -> Option<Self>

The value buf canonically encodes, with nothing left over.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.