pub struct RatInterval { /* private fields */ }Expand description
A closed interval of exact rationals, lo <= hi (Appendix H.3).
Because the endpoints are exact rationals, +, - and x on intervals are
themselves exact — there is nothing to round outward. Outward rounding enters
at exactly two places, and both are explicit:
RatInterval::sqrt_enclosure, which uses the directed integer roots;- fixed-point scaling, where the scale is declared and recorded.
That is a stronger position than a float interval library can take, and it is what lets Rule X promise a certified enclosure rather than a tolerance.
Implementations§
Source§impl RatInterval
impl RatInterval
Sourcepub fn new(lo: Ratio, hi: Ratio) -> Result<RatInterval>
pub fn new(lo: Ratio, hi: Ratio) -> Result<RatInterval>
Construct, rejecting inversion with UCAL-E0022.
Sourcepub fn exact(v: Ratio) -> RatInterval
pub fn exact(v: Ratio) -> RatInterval
The degenerate interval at an exact value.
Sourcepub fn contains_zero(&self) -> bool
pub fn contains_zero(&self) -> bool
Whether zero is inside the interval. Division requires this to be false (Appendix H.3).
Sourcepub fn add(&self, other: &RatInterval) -> Result<RatInterval>
pub fn add(&self, other: &RatInterval) -> Result<RatInterval>
Interval addition. Exact: lo with lo, hi with hi.
Sourcepub fn sub(&self, other: &RatInterval) -> Result<RatInterval>
pub fn sub(&self, other: &RatInterval) -> Result<RatInterval>
Interval subtraction, [lo - other.hi, hi - other.lo].
Sourcepub fn mul(&self, other: &RatInterval) -> Result<RatInterval>
pub fn mul(&self, other: &RatInterval) -> Result<RatInterval>
Interval multiplication: the min and max of the four endpoint products.
With non-negative endpoints this reduces to lo*lo and hi*hi, but the
general form is computed anyway so the method stays correct if the
endpoint domain is ever widened.
Sourcepub fn div(&self, other: &RatInterval) -> Result<RatInterval>
pub fn div(&self, other: &RatInterval) -> Result<RatInterval>
Interval division. UCAL-E0070 if the divisor interval contains zero.
Sourcepub fn sqrt_enclosure(&self, scale_digits: u32) -> Result<(RatInterval, u32)>
pub fn sqrt_enclosure(&self, scale_digits: u32) -> Result<(RatInterval, u32)>
A certified enclosure of the square root, at a declared fixed-point scale (Appendix H.2).
Computes [isqrt_floor(lo x S^2) / S, isqrt_ceil(hi x S^2) / S], which
provably contains the true root of every value in the interval. The scale
is a parameter rather than a constant because different queries need
different precision (D-6), and it is returned alongside the result so it
can be recorded — CosmoResult carries it as scale.
Widening the interval is always sound; narrowing it would not be. Every rounding here goes outward.
Sourcepub fn hull(&self, other: &RatInterval) -> RatInterval
pub fn hull(&self, other: &RatInterval) -> RatInterval
The smallest interval containing both.
Trait Implementations§
Source§impl Clone for RatInterval
impl Clone for RatInterval
Source§fn clone(&self) -> RatInterval
fn clone(&self) -> RatInterval
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more