Skip to main content

RatInterval

Struct RatInterval 

Source
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:

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

Source

pub fn new(lo: Ratio, hi: Ratio) -> Result<RatInterval>

Construct, rejecting inversion with UCAL-E0022.

Source

pub fn exact(v: Ratio) -> RatInterval

The degenerate interval at an exact value.

Source

pub fn lo(&self) -> &Ratio

Lower bound.

Source

pub fn hi(&self) -> &Ratio

Upper bound.

Source

pub fn is_exact(&self) -> bool

Whether the interval is a single point.

Source

pub fn width(&self) -> Result<Ratio>

hi - lo.

Source

pub fn contains(&self, v: &Ratio) -> bool

Whether the interval contains a value.

Source

pub fn contains_zero(&self) -> bool

Whether zero is inside the interval. Division requires this to be false (Appendix H.3).

Source

pub fn add(&self, other: &RatInterval) -> Result<RatInterval>

Interval addition. Exact: lo with lo, hi with hi.

Source

pub fn sub(&self, other: &RatInterval) -> Result<RatInterval>

Interval subtraction, [lo - other.hi, hi - other.lo].

Source

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.

Source

pub fn div(&self, other: &RatInterval) -> Result<RatInterval>

Interval division. UCAL-E0070 if the divisor interval contains zero.

Source

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.

Source

pub fn hull(&self, other: &RatInterval) -> RatInterval

The smallest interval containing both.

Trait Implementations§

Source§

impl Clone for RatInterval

Source§

fn clone(&self) -> RatInterval

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for RatInterval

Source§

impl Debug for RatInterval

Source§

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

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

impl Eq for RatInterval

Source§

impl PartialEq for RatInterval

Source§

fn eq(&self, other: &RatInterval) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for RatInterval

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<U> As for U

Source§

fn as_<T>(self) -> T
where T: CastFrom<U>, U: Sized,

Casts self to type T. The semantics of numeric casting with the as operator are followed, so <T as As>::as_::<U> can be used in the same way as T as U for numeric conversions. 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, 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.