Interval

Struct Interval 

Source
pub struct Interval<BOUND: PartialOrd> {
    pub lo: BOUND,
    pub hi: BOUND,
}
Expand description

Interval struct.

Represents a set where each element x satisfies lo <= x && x <= hi.

Fields§

§lo: BOUND

Inclusive lower bound.

§hi: BOUND

Inclusive upper bound.

Implementations§

Source§

impl<BOUND: Float> Interval<BOUND>

Source

pub fn new(lo: BOUND, hi: BOUND) -> Self

Constructs a new interval from given bounds.

Lower bound must be less than or equal to upper bound. Only exception is when they are both NaNs, in which case a NaN (empty) interval is created.

Cases where both bounds are negative infinity or positive infinity are not allowed as these are empty sets. If you want to represent an empty set, use Interval::nan().

Source

pub fn minimal_cover(intervals: Vec<Self>, precision: usize) -> Self

Constructs the minimal interval that covers all of the given intervals.

Source

pub fn singleton(val: BOUND) -> Self

Constructs a singleton interval (an interval with only one element).

Source

pub fn zero(precision: usize) -> Self

Constructs an interval that contains only zero.

Source

pub fn one(precision: usize) -> Self

Constructs an interval that contains only one.

Source

pub fn nan(precision: usize) -> Self

Constructs a NaN (empty) interval.

Source

pub fn whole(precision: usize) -> Self

Constructs an interval that contains all numbers.

Source

pub fn from_with_prec(val: f64, precision: usize) -> Self

Constructs an interval from a float with given precision.

Source

pub fn from_str_with_prec( s: &str, precision: usize, ) -> Result<Self, ParseIntervalError>

Constructs an interval by parsing a string.

Accepts INTERVAL according to the rule below.

INTERVAL = FLOAT | ‘<’ FLOAT ‘,’ FLOAT ‘>’

Source

pub fn sign_class(&self) -> SignClass

Returns the sign class of self.

Source

pub fn precision(&self) -> usize

Returns the precision of self.

Source

pub fn size(&self) -> Self

Returns the difference between the upper bound and the lower bound of self.

As the result is not always exactly representable as BOUND, an interval is returned instead.

Source

pub fn is_singleton(&self) -> bool

Whether self is a singleton interval (an interval containing only one element).

Source

pub fn is_zero(&self) -> bool

Whether self contains only zero.

Source

pub fn is_nan(&self) -> bool

Whether self is NaN (empty).

Source

pub fn is_whole(&self) -> bool

Whether self contains all numbers.

Source

pub fn has_zero(&self) -> bool

Whether self contains zero.

Source

pub fn split(self, val: BOUND) -> (Self, Self)

Cuts self into two at val and returns the left and right pieces as a pair.

If self lies on only one side of val, the non-existent side will be a NaN interval.

Source§

impl<BOUND: Float> Interval<BOUND>

Source

pub fn div_multi(self, rhs: Self) -> Vec<Self>

Divides self by rhs and returns a vector of intervals minimally covering the result.

Source§

impl<BOUND: Float> Interval<BOUND>

Source

pub fn pow_multi(self, rhs: Self) -> Vec<Self>

Computes self raised to the power rhs and returns a vector of intervals minimally covering the result.

Trait Implementations§

Source§

impl<BOUND: Float> Add for Interval<BOUND>

Source§

type Output = Interval<BOUND>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl<BOUND: Clone + PartialOrd> Clone for Interval<BOUND>

Source§

fn clone(&self) -> Interval<BOUND>

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<BOUND: Debug + PartialOrd> Debug for Interval<BOUND>

Source§

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

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

impl<BOUND: Float> Display for Interval<BOUND>

Source§

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

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

impl<BOUND: Float> Div for Interval<BOUND>

Source§

type Output = Interval<BOUND>

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl<BOUND: Float> From<f64> for Interval<BOUND>

Source§

fn from(val: f64) -> Self

Converts to this type from the input type.
Source§

impl<BOUND: Float> FromStr for Interval<BOUND>

Source§

type Err = ParseIntervalError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl<BOUND: Float> Into<(BOUND, BOUND)> for Interval<BOUND>

Source§

fn into(self) -> (BOUND, BOUND)

Converts this type into the (usually inferred) input type.
Source§

impl<BOUND: Float> Mul for Interval<BOUND>

Source§

type Output = Interval<BOUND>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<BOUND: Float> Neg for Interval<BOUND>

Source§

type Output = Interval<BOUND>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<BOUND: Float> PartialEq for Interval<BOUND>

Source§

fn eq(&self, rhs: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<BOUND: Float> Sub for Interval<BOUND>

Source§

type Output = Interval<BOUND>

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl<BOUND: Float> Transc for Interval<BOUND>

Source§

type Output = Interval<BOUND>

Output type.
Source§

fn log(self) -> Self::Output

Computes the natural logarithm of self.
Source§

fn exp(self) -> Self::Output

Computes the natural exponential of self.
Source§

fn pow(self, rhs: Self) -> Self::Output

Computes self raised to the power rhs.

Auto Trait Implementations§

§

impl<BOUND> Freeze for Interval<BOUND>
where BOUND: Freeze,

§

impl<BOUND> RefUnwindSafe for Interval<BOUND>
where BOUND: RefUnwindSafe,

§

impl<BOUND> Send for Interval<BOUND>
where BOUND: Send,

§

impl<BOUND> Sync for Interval<BOUND>
where BOUND: Sync,

§

impl<BOUND> Unpin for Interval<BOUND>
where BOUND: Unpin,

§

impl<BOUND> UnwindSafe for Interval<BOUND>
where BOUND: UnwindSafe,

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.