Skip to main content

Interval

Struct Interval 

Source
pub struct Interval {
    lo: f64,
    hi: f64,
}
Expand description

A closed interval [lo, hi] with f64 endpoints, or the empty set (invariants I1–I3). Operations round outward by computed directed rounding (Chapter 11.9).

An interval is a set of real numbers: an infinite endpoint means “unbounded on that side”. Not xingo_sparse::Real: intervals have no total order and their operations no single rounding (D-0080, Q2). Not PartialOrd either: the comparisons are the named predicates below, whose meaning cannot be misread.

use xingo_extprec::Interval;
let tenth = Interval::point(1.0) / 10.0; // encloses the real 1/10
assert!(tenth.inf() < tenth.sup() && tenth.contains(0.1));
let one = tenth * 10.0;
assert!(one.contains(1.0) && one.certainly_within(1.0 + 1e-15));

Fields§

§lo: f64§hi: f64

Implementations§

Source§

impl Interval

Source

pub const ENTIRE: Self

[−∞, +∞]: “nothing is known” (invariant C3).

Source

pub const EMPTY: Self

The empty set (stored as [+∞, −∞]; every operation propagates it).

Source

pub const ZERO: Self

[0, 0].

Source

fn raw(lo: f64, hi: f64) -> Self

The interval of the pair, which the caller proved well-formed.

Source

pub fn new(lo: f64, hi: f64) -> Result<Self, InvalidInterval>

[lo, hi].

§Errors

InvalidInterval when (I2) fails.

Source

pub fn point(x: f64) -> Self

[x, x]. Panics on NaN — and on ±∞, which is not a real number (it would violate (I2)).

Source

pub fn mid_rad(m: f64, r: f64) -> Self

[m − r, m + r] rounded outward; r ≥ 0 (r = +∞ gives Interval::ENTIRE, and so does an infinite m). Panics if m or r is NaN or r < 0.

Source

pub fn enclose(x: DoubleDouble) -> Self

The tightest interval containing the double-double x: [hi, hi] if lo = 0, else the two neighbours of x in F. An infinite or NaN x — the trace of an overflow or of an invalid operation, not a real number — gives Interval::ENTIRE (invariant C3).

Source

pub const fn inf(self) -> f64

The lower endpoint (+∞ for the empty set).

Source

pub const fn sup(self) -> f64

The upper endpoint (−∞ for the empty set).

Source

pub fn is_empty(self) -> bool

The empty set.

Source

pub fn mid(self) -> f64

An f64 in the interval nearest its midpoint (finite when the interval is bounded; 0 for Interval::ENTIRE). For a half-line, the finite f64 farthest out (±Ω, as in IEEE 1788); NaN for the empty set.

Source

pub fn width(self) -> f64

sup − inf rounded up (+∞ when unbounded, NaN when empty).

Source

pub fn mag(self) -> f64

max{|x| : x ∈ X}, the magnitude (exact; +∞ when unbounded, NaN when empty).

Source

pub fn mig(self) -> f64

min{|x| : x ∈ X}, the mignitude (exact; NaN when empty).

Source

pub fn contains(self, x: f64) -> bool

x ∈ X (false for a NaN or infinite x: the elements are real numbers).

Source

pub fn is_subset_of(self, other: Self) -> bool

X ⊆ Y (∅ is a subset of every interval).

Source

pub fn certainly_le(self, b: f64) -> bool

Every element of X is ≤ b: certainly x ≤ b. false for the empty set and for a NaN b (Chapter 11.9: nothing was proved).

Source

pub fn certainly_ge(self, a: f64) -> bool

Every element of X is ≥ a: certainly x ≥ a. false for the empty set and for a NaN a.

Source

pub fn certainly_within(self, t: f64) -> bool

X ⊆ [−t, t]: certainly |x| ≤ t (a verified tolerance test). false for the empty set and for a NaN t.

Source

pub fn hull(self, other: Self) -> Self

The hull [min inf, max sup] (the union’s enclosure).

Source

pub fn intersection(self, other: Self) -> Self

The intersection (possibly Interval::EMPTY).

Source

pub fn abs(self) -> Self

{|x| : x ∈ X}.

Source

pub fn square(self) -> Self

{x² : x ∈ X} (tighter than X · X when 0 ∈ X).

Source

pub fn sqrt(self) -> Self

{√x : x ∈ X, x ≥ 0} (Interval::EMPTY when sup < 0).

Source

pub fn check_invariants(self) -> Result<(), &'static str>

Invariant (I2).

§Errors

The text of the violated invariant.

Trait Implementations§

Source§

impl Add for Interval

Step I1.

Source§

type Output = Interval

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self

Performs the + operation. Read more
Source§

impl Add<Interval> for f64

With a point left operand: y + X is [y, y] + X (invariant I4). A NaN or infinite y gives Interval::ENTIRE.

Source§

type Output = Interval

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Interval) -> Interval

Performs the + operation. Read more
Source§

impl Add<f64> for Interval

With a point right operand ([x, x], exact): half the work (step I6). A NaN or infinite x gives Interval::ENTIRE.

Source§

type Output = Interval

The resulting type after applying the + operator.
Source§

fn add(self, rhs: f64) -> Self

Performs the + operation. Read more
Source§

impl AddAssign for Interval

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl AddAssign<f64> for Interval

Source§

fn add_assign(&mut self, rhs: f64)

Performs the += operation. Read more
Source§

impl Clone for Interval

Source§

fn clone(&self) -> Self

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 Interval

Source§

impl Debug for Interval

Source§

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

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

impl Display for Interval

[a, b], or ∅ (Algorithm D of Chapter 11.9). Without a precision each endpoint is the shortest text that reads back as the same f64 (with the flags of the formatter): the output identifies the interval. With a precision ({:.3}) the endpoints are rounded outward: the printed pair, read as exact decimals, contains the interval. The width and the fill are then ignored.

Source§

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

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

impl Div for Interval

Steps I3 and I4: when the divisor contains zero the result is Interval::ENTIRE, or a half-line when zero is an endpoint of the divisor and the dividend has one sign — the hull of the quotients by the nonzero elements, never a panic. ([0, 0] / Y is [0, 0] unless Y = [0, 0].)

Source§

type Output = Interval

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Self) -> Self

Performs the / operation. Read more
Source§

impl Div<Interval> for f64

With a point left operand: y / X is [y, y] / X (invariant I4; steps I3 and I4 when X contains zero). A NaN or infinite y gives Interval::ENTIRE.

Source§

type Output = Interval

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Interval) -> Interval

Performs the / operation. Read more
Source§

impl Div<f64> for Interval

With a point right operand ([x, x], exact): half the work (step I6). A NaN, infinite or zero x gives Interval::ENTIRE.

Source§

type Output = Interval

The resulting type after applying the / operator.
Source§

fn div(self, rhs: f64) -> Self

Performs the / operation. Read more
Source§

impl DivAssign for Interval

Source§

fn div_assign(&mut self, rhs: Self)

Performs the /= operation. Read more
Source§

impl DivAssign<f64> for Interval

Source§

fn div_assign(&mut self, rhs: f64)

Performs the /= operation. Read more
Source§

impl From<f64> for Interval

The interval of one f64, total: [x, x] for a finite x, and Interval::ENTIRE for a NaN or an infinite x.

This differs from Interval::point, which panics on a NaN or an infinity, on purpose: From must not fail (the standard library’s contract for the trait), and “nothing is known” is what the operators already return for a scalar operand that is not a real number — so Interval::from(y) ∘ X equals y ∘ X for every y and every non-empty X. Use point when a non-real argument is a bug to be caught, from when it is data to be carried.

Source§

fn from(x: f64) -> Self

Converts to this type from the input type.
Source§

impl LowerExp for Interval

[a, b] in scientific notation ({:e}), or ∅; as Display: shortest round-trip endpoints without a precision, outward-rounded endpoints with one ({:.3e}: four significant digits).

Source§

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

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

impl Mul for Interval

Step I2.

Source§

type Output = Interval

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self

Performs the * operation. Read more
Source§

impl Mul<Interval> for f64

With a point left operand: y · X is [y, y] · X (invariant I4). A NaN or infinite y gives Interval::ENTIRE.

Source§

type Output = Interval

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Interval) -> Interval

Performs the * operation. Read more
Source§

impl Mul<f64> for Interval

With a point right operand ([x, x], exact): half the work (step I6). A NaN or infinite x gives Interval::ENTIRE.

Source§

type Output = Interval

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: f64) -> Self

Performs the * operation. Read more
Source§

impl MulAssign for Interval

Source§

fn mul_assign(&mut self, rhs: Self)

Performs the *= operation. Read more
Source§

impl MulAssign<f64> for Interval

Source§

fn mul_assign(&mut self, rhs: f64)

Performs the *= operation. Read more
Source§

impl Neg for Interval

{−x : x ∈ X}, exact.

Source§

type Output = Interval

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self

Performs the unary - operation. Read more
Source§

impl PartialEq for Interval

Source§

fn eq(&self, other: &Self) -> 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 Interval

Source§

impl Sub for Interval

Step I1.

Source§

type Output = Interval

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self

Performs the - operation. Read more
Source§

impl Sub<Interval> for f64

With a point left operand: y − X is [y, y] − X (invariant I4). A NaN or infinite y gives Interval::ENTIRE.

Source§

type Output = Interval

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Interval) -> Interval

Performs the - operation. Read more
Source§

impl Sub<f64> for Interval

With a point right operand ([x, x], exact): half the work (step I6). A NaN or infinite x gives Interval::ENTIRE.

Source§

type Output = Interval

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: f64) -> Self

Performs the - operation. Read more
Source§

impl SubAssign for Interval

Source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
Source§

impl SubAssign<f64> for Interval

Source§

fn sub_assign(&mut self, rhs: f64)

Performs the -= operation. Read more

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.