pub struct ExactReal { /* private fields */ }Expand description
A computable real number. See the module documentation.
Implementations§
Source§impl ExactReal
impl ExactReal
pub fn from_i64(n: i64) -> ExactReal
pub fn from_rational(r: Rational) -> ExactReal
pub fn from_algebraic(a: Algebraic) -> ExactReal
Sourcepub fn from_f64(f: f64) -> Option<ExactReal>
pub fn from_f64(f: f64) -> Option<ExactReal>
The exact value of a finite float; None for NaN and the infinities.
pub fn pi() -> ExactReal
pub fn e() -> ExactReal
Sourcepub fn exact_algebraic(&self) -> Option<Algebraic>
pub fn exact_algebraic(&self) -> Option<Algebraic>
The value as an algebraic number, when it is one exactly.
Sourcepub fn is_exactly_zero(&self) -> bool
pub fn is_exactly_zero(&self) -> bool
True only when an exact form proves the value is zero.
Sourcepub fn is_exact_form(&self) -> bool
pub fn is_exact_form(&self) -> bool
Held in a form whose equality is decidable.
pub fn add(&self, o: &ExactReal) -> ExactReal
pub fn neg(&self) -> ExactReal
pub fn sub(&self, o: &ExactReal) -> ExactReal
pub fn mul(&self, o: &ExactReal) -> ExactReal
Sourcepub fn recip(&self) -> Result<ExactReal, RealError>
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.
pub fn div(&self, o: &ExactReal) -> Result<ExactReal, RealError>
Sourcepub fn defined(
definition: Definition,
name: &str,
source: Arc<dyn Approximant>,
) -> ExactReal
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.
Sourcepub fn is_transmissible(&self) -> bool
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.
Sourcepub fn flow(
field: &Field,
start: &[ExactReal],
t: &Rational,
) -> Option<Vec<ExactReal>>
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.
Sourcepub fn sqrt(&self) -> Result<ExactReal, RealError>
pub fn sqrt(&self) -> Result<ExactReal, RealError>
The nonnegative square root; exact where ExactReal::nth_root is.
Sourcepub fn nth_root(&self, n: u32) -> Result<ExactReal, RealError>
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.
pub fn exp(&self) -> ExactReal
Sourcepub fn log(&self) -> Result<ExactReal, RealError>
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).
pub fn sin(&self) -> ExactReal
pub fn cos(&self) -> ExactReal
pub fn cosh(&self) -> ExactReal
pub fn sinh(&self) -> ExactReal
Sourcepub fn enclosure(&self, bits: u32) -> Result<(Rational, Rational), RealError>
pub fn enclosure(&self, bits: u32) -> Result<(Rational, Rational), RealError>
A closed interval holding the value, at most 2^-bits wide.
Sourcepub fn compare(&self, o: &ExactReal, budget: u32) -> Result<Ordering, RealError>
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.
Sourcepub fn compare_within(
&self,
o: &ExactReal,
tolerance: &Rational,
) -> Result<Closeness, RealError>
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).
Sourcepub fn floor(&self, budget: u32) -> Result<BigInt, RealError>
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.
Sourcepub fn to_decimal(&self, sig: u32) -> String
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.
Sourcepub fn try_to_decimal(&self, sig: u32) -> Result<String, RealError>
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.
Trait Implementations§
Source§impl ExactCodec for ExactReal
impl ExactCodec for ExactReal
Source§fn write(&self, out: &mut Vec<u8>)
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.
fn read(buf: &[u8], pos: &mut usize) -> Option<Self>
fn to_bytes(&self) -> Vec<u8> ⓘ
Source§fn from_bytes(buf: &[u8]) -> Option<Self>
fn from_bytes(buf: &[u8]) -> Option<Self>
buf canonically encodes, with nothing left over.