Skip to main content

Interval

Struct Interval 

Source
pub struct Interval { /* private fields */ }
Expand description

An interval with f64 bounds.

It is sometimes referred to as a bare interval in contrast to a decorated interval (DecInterval).

Implementationsยง

Sourceยง

impl Interval

Source

pub fn abs(self) -> Self

Returns the absolute value of self.

The domain and the range of the point function are:

DomainRange
$\R$$[0, โˆž)$
Source

pub fn max(self, rhs: Self) -> Self

Returns the maximum of self and rhs.

The domain and the range of the point function are:

DomainRange
$\R^2$$\R$
Source

pub fn min(self, rhs: Self) -> Self

Returns the minimum of self and rhs.

The domain and the range of the point function are:

DomainRange
$\R^2$$\R$
Sourceยง

impl Interval

Source

pub fn mul_rev_to_pair(self, numerator: Self) -> [Self; 2]

Returns the reverse multiplication $\numerator \setdivโ€ฒ \self$ (beware the order of the arguments) as an array of two intervals. The operation is also known as two-output division in IEEE Std 1788-2015.

For intervals $๐’™$ and $๐’š$, the reverse multiplication is defined as:

$$ ๐’™ \setdivโ€ฒ ๐’š = \set{z โˆˆ \R โˆฃ โˆƒy โˆˆ ๐’š : zy โˆˆ ๐’™}. $$

For comparison, the standard division is defined as:

$$ \begin{align*} ๐’™ \setdiv ๐’š &= \set{x / y โˆฃ (x, y) โˆˆ ๐’™ ร— ๐’š โˆ– \set 0} \\ &= \set{z โˆˆ \R โˆฃ โˆƒy โˆˆ ๐’š โˆ– \set 0 : zy โˆˆ ๐’™}. \end{align*} $$

The interval division $๐’™ / ๐’š$ is an enclosure of $๐’™ \setdiv ๐’š$. A notable difference between two definitions is that when $๐’™ = ๐’š = \set 0$, $๐’™ \setdiv ๐’š = โˆ…$, while $๐’™ \setdivโ€ฒ ๐’š = \R$.

The function returns:

  • [Interval::EMPTY; 2] if $\numerator \setdivโ€ฒ \self$ is empty;
  • [z, Interval::EMPTY] if $\numerator \setdivโ€ฒ \self$ has one component $๐’›$, where z is the tightest enclosure of $๐’›$;
  • [z1, z2] if $\numerator \setdivโ€ฒ \self$ has two components $๐’›โ‚$ and $๐’›โ‚‚$ ordered so that $\sup ๐’›โ‚ โ‰ค \inf ๐’›โ‚‚$, where z1 and z2 are the tightest enclosures of $๐’›โ‚$ and $๐’›โ‚‚$, respectively.

When $\self โ‰  โˆ… โˆง \numerator โ‰  โˆ…$, the number of components $\numerator \setdivโ€ฒ \self$ has are summarized as:

$0 โˆˆ \numerator$$0 โˆ‰ \numerator$
$0 โˆˆ \self$10, 1, or 2
$0 โˆ‰ \self$11
ยงExamples
use inari::{Interval as I, const_interval as c};
let zero = c!(0.0, 0.0);
assert_eq!(zero.mul_rev_to_pair(c!(1.0, 2.0)), [I::EMPTY; 2]);
assert_eq!(zero.mul_rev_to_pair(c!(0.0, 2.0)), [I::ENTIRE, I::EMPTY]);
assert_eq!(zero.mul_rev_to_pair(zero), [I::ENTIRE, I::EMPTY]);
let x = c!(1.0, 2.0);
assert_eq!(I::ENTIRE.mul_rev_to_pair(x), [c!(f64::NEG_INFINITY, 0.0), c!(0.0, f64::INFINITY)]);
assert_eq!(c!(1.0, 1.0).mul_rev_to_pair(x), [x, I::EMPTY]);
assert_eq!(c!(1.0, f64::INFINITY).mul_rev_to_pair(c!(1.0, 1.0)),
           [c!(0.0, 1.0), I::EMPTY]);
assert_eq!(c!(-1.0, 1.0).mul_rev_to_pair(c!(1.0, 2.0)),
           [c!(f64::NEG_INFINITY, -1.0), c!(1.0, f64::INFINITY)]);
assert_eq!(c!(-1.0, 1.0).mul_rev_to_pair(zero), [I::ENTIRE, I::EMPTY]);
Source

pub fn cancel_minus(self, rhs: Self) -> Self

Returns the tightest interval z such that rhs $+$ z $โЇ$ self, if both self and rhs are bounded and the width of self is greater than or equal to that of rhs. Otherwise, returns Interval::ENTIRE.

Even when x.cancel_minus(y) is not Interval::ENTIRE, its value is generally different from x - y, as the latter gives the tightest enclosure of x $-$ y, while the former does not always enclose x $-$ y. In such case, x.cancel_minus(y) $โІ$ x - y holds, but generally not the equality.

ยงExamples

Getting an enclosure of a partial sum omitting a single term from their total:

use inari::*;
let x = interval!("[0.1, 0.2]").unwrap();
let y = interval!("[0.3, 0.4]").unwrap();
let z = interval!("[0.5, 0.6]").unwrap();
let sum = x + y + z;
assert!((y + z).subset(sum.cancel_minus(x)));
assert!((x + z).subset(sum.cancel_minus(y)));
assert!((x + y).subset(sum.cancel_minus(z)));

sum.cancel_minus(x) is a subset of sum - x:

assert!(sum.cancel_minus(x).subset(sum - x));

But the inverse does not hold in general:

โ“˜
assert!((sum - x).subset(sum.cancel_minus(x)));

sum.cancel_minus(x), etc. returns Interval::ENTIRE when sum is unbounded:

use inari::*;
let x = const_interval!(1.0, 2.0);
let y = const_interval!(3.0, f64::MAX);
let sum = x + y;
assert_eq!(sum.cancel_minus(x), Interval::ENTIRE);
assert_eq!(sum.cancel_minus(y), Interval::ENTIRE);

sum.cancel_minus(x) returns Interval::ENTIRE when the width of โ€œsumโ€ is less than that of x:

use inari::*;
let x = const_interval!(1.0, 2.0);
let sum = const_interval!(4.0, 4.5);
assert_eq!(sum.cancel_minus(x), Interval::ENTIRE);
Source

pub fn cancel_plus(self, rhs: Self) -> Self

x.cancel_plus(y) is equivalent to x.cancel_minus(-y).

See Interval::cancel_minus for more information.

Source

pub fn mul_add(self, rhs: Self, addend: Self) -> Self

Returns $(\self ร— \rhs) + \addend$.

The domain and the range of the point function are:

DomainRange
$\R^3$$\R$
Source

pub fn recip(self) -> Self

Returns the multiplicative inverse of self.

The domain and the range of the point function are:

DomainRange
$\R โˆ– \set 0$$\R โˆ– \set 0$
Source

pub fn sqr(self) -> Self

Returns the square of self.

The domain and the range of the point function are:

DomainRange
$\R$$[0, โˆž)$
Source

pub fn sqrt(self) -> Self

Returns the principal square root of self.

The domain and the range of the point function are:

DomainRange
$[0, โˆž)$$[0, โˆž)$
Sourceยง

impl Interval

Source

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

Returns true if rhs is a member of self: $\rhs โˆˆ \self$.

The result is false whenever rhs is infinite or NaN.

ยงExamples
use inari::*;
assert!(const_interval!(1.0, 2.0).contains(1.0));
assert!(!Interval::EMPTY.contains(1.0));
assert!(Interval::ENTIRE.contains(1.0));

$ยฑโˆž$ and NaN are not real numbers, thus do not belong to any interval:

use inari::*;
assert!(!Interval::ENTIRE.contains(f64::INFINITY));
assert!(!Interval::ENTIRE.contains(f64::NEG_INFINITY));
assert!(!Interval::ENTIRE.contains(f64::NAN));
Source

pub fn disjoint(self, rhs: Self) -> bool

Returns true if self and rhs are disjoint:

$$ \self โˆฉ \rhs = โˆ…, $$

or equivalently,

$$ โˆ€x โˆˆ \self, โˆ€y โˆˆ \rhs : x โ‰  y, $$

or equivalently,

$\rhs = โˆ…$$\rhs = [c, d]$
$\self = โˆ…$truetrue
$\self = [a, b]$true$b < c โˆจ d < a$
ยงExamples
use inari::*;
assert!(const_interval!(1.0, 2.0).disjoint(const_interval!(3.0, 4.0)));
assert!(!const_interval!(1.0, 3.0).disjoint(const_interval!(3.0, 4.0)));
assert!(!const_interval!(1.0, 5.0).disjoint(const_interval!(3.0, 4.0)));
assert!(Interval::EMPTY.disjoint(Interval::EMPTY));
assert!(Interval::EMPTY.disjoint(Interval::ENTIRE));
Source

pub fn interior(self, rhs: Self) -> bool

Returns true if self is interior to rhs:

$$ (โˆ€x โˆˆ \self, โˆƒy โˆˆ \rhs : x < y) โˆง (โˆ€x โˆˆ \self, โˆƒy โˆˆ \rhs : y < x), $$

or equivalently,

$\rhs = โˆ…$$\rhs = [c, d]$
$\self = โˆ…$truetrue
$\self = [a, b]$false$c <โ€ฒ a โˆง b <โ€ฒ d$

where $<โ€ฒ$ is defined as:

$$ x <โ€ฒ y :โŸบ x < y โˆจ x = y = -โˆž โˆจ x = y = +โˆž. $$

ยงExamples
use inari::*;
assert!(const_interval!(1.1, 1.9).interior(const_interval!(1.0, 2.0)));
assert!(!const_interval!(1.1, 2.0).interior(const_interval!(1.0, 2.0)));
assert!(Interval::EMPTY.interior(Interval::EMPTY));
assert!(Interval::ENTIRE.interior(Interval::ENTIRE));
Source

pub fn is_common_interval(self) -> bool

Returns true if self is nonempty and bounded.

ยงExamples
use inari::*;
assert!(const_interval!(1.0, 2.0).is_common_interval());
assert!(!const_interval!(1.0, f64::INFINITY).is_common_interval());
assert!(!Interval::EMPTY.is_common_interval());
assert!(!Interval::ENTIRE.is_common_interval());
Source

pub fn is_empty(self) -> bool

Returns true if self is empty: $\self = โˆ…$.

ยงExamples
use inari::*;
assert!(!const_interval!(1.0, 1.0).is_empty());
assert!(Interval::EMPTY.is_empty());
assert!(!Interval::ENTIRE.is_empty());
Source

pub fn is_entire(self) -> bool

Returns true if $\self = [-โˆž, +โˆž]$.

ยงExamples
use inari::*;
assert!(!const_interval!(1.0, f64::INFINITY).is_entire());
assert!(!Interval::EMPTY.is_entire());
assert!(Interval::ENTIRE.is_entire());
Source

pub fn is_singleton(self) -> bool

Returns true if self consists of a single real number:

$$ โˆƒx โˆˆ โ„ : \self = [x, x]. $$

The result is false whenever self is empty or unbounded.

ยงExamples
use inari::*;
assert!(const_interval!(1.0, 1.0).is_singleton());
assert!(!const_interval!(1.0, 2.0).is_singleton());
assert!(!Interval::EMPTY.is_singleton());
assert!(!Interval::ENTIRE.is_singleton());

0.1 is not representable as a f64 number:

use inari::*;
// The singleton interval that consists of the closest [`f64`] number to 0.1.
assert!(const_interval!(0.1, 0.1).is_singleton());
// The tightest interval that encloses 0.1.
#[cfg(feature = "gmp")]
assert!(!interval!("[0.1, 0.1]").unwrap().is_singleton());
Source

pub fn less(self, rhs: Self) -> bool

Returns true if self is weakly less than rhs:

$$ (โˆ€x โˆˆ \self, โˆƒy โˆˆ \rhs : x โ‰ค y) โˆง (โˆ€y โˆˆ \rhs, โˆƒx โˆˆ \self : x โ‰ค y), $$

or equivalently,

$\rhs = โˆ…$$\rhs = [c, d]$
$\self = โˆ…$truefalse
$\self = [a, b]$false$a โ‰ค c โˆง b โ‰ค d$
ยงExamples
use inari::*;
assert!(const_interval!(1.0, 2.0).less(const_interval!(3.0, 4.0)));
assert!(const_interval!(1.0, 3.0).less(const_interval!(2.0, 4.0)));
assert!(const_interval!(1.0, 4.0).less(const_interval!(1.0, 4.0)));
assert!(Interval::EMPTY.less(Interval::EMPTY));
assert!(!Interval::EMPTY.less(Interval::ENTIRE));
assert!(!Interval::ENTIRE.less(Interval::EMPTY));
assert!(Interval::ENTIRE.less(Interval::ENTIRE));
Source

pub fn precedes(self, rhs: Self) -> bool

Returns true if self is to the left of rhs but may touch it:

$$ โˆ€x โˆˆ \self, โˆ€y โˆˆ \rhs : x โ‰ค y, $$

or equivalently,

$\rhs = โˆ…$$\rhs = [c, d]$
$\self = โˆ…$truetrue
$\self = [a, b]$true$b โ‰ค c$
ยงExamples
use inari::*;
assert!(const_interval!(1.0, 2.0).precedes(const_interval!(3.0, 4.0)));
assert!(const_interval!(1.0, 3.0).precedes(const_interval!(3.0, 4.0)));
assert!(!const_interval!(1.0, 3.0).precedes(const_interval!(2.0, 4.0)));
assert!(Interval::EMPTY.precedes(Interval::EMPTY));
assert!(Interval::EMPTY.precedes(Interval::ENTIRE));
assert!(Interval::ENTIRE.precedes(Interval::EMPTY));
assert!(!Interval::ENTIRE.precedes(Interval::ENTIRE));
Source

pub fn strict_less(self, rhs: Self) -> bool

Returns true if self is strictly less than rhs:

$$ (โˆ€x โˆˆ \self, โˆƒy โˆˆ \rhs : x < y) โˆง (โˆ€y โˆˆ \self, โˆƒx โˆˆ \rhs : x < y), $$

or equivalently,

$\rhs = โˆ…$$\rhs = [c, d]$
$\self = โˆ…$truefalse
$\self = [a, b]$false$a <โ€ฒ c โˆง b <โ€ฒ d$

where $<โ€ฒ$ is defined as:

$$ x <โ€ฒ y :โŸบ x < y โˆจ x = y = -โˆž โˆจ x = y = +โˆž. $$

ยงExamples
use inari::*;
assert!(const_interval!(1.0, 2.0).strict_less(const_interval!(3.0, 4.0)));
assert!(const_interval!(1.0, 3.0).strict_less(const_interval!(2.0, 4.0)));
assert!(!const_interval!(1.0, 4.0).strict_less(const_interval!(2.0, 4.0)));
assert!(const_interval!(1.0, f64::INFINITY).strict_less(const_interval!(2.0, f64::INFINITY)));
assert!(Interval::EMPTY.strict_less(Interval::EMPTY));
assert!(!Interval::EMPTY.strict_less(Interval::ENTIRE));
assert!(!Interval::ENTIRE.strict_less(Interval::EMPTY));
assert!(Interval::ENTIRE.strict_less(Interval::ENTIRE));
Source

pub fn strict_precedes(self, rhs: Self) -> bool

Returns true if self is strictly to the left of rhs:

$$ โˆ€x โˆˆ \self, โˆ€y โˆˆ \rhs : x < y, $$

or equivalently,

$\rhs = โˆ…$$\rhs = [c, d]$
$\self = โˆ…$truetrue
$\self = [a, b]$true$b < c$
Source

pub fn subset(self, rhs: Self) -> bool

Returns true if self is a subset of rhs:

$$ \self โІ \rhs, $$

or equivalently,

$$ โˆ€x โˆˆ \self, โˆƒy โˆˆ \rhs : x = y, $$

or equivalently,

$\rhs = โˆ…$$\rhs = [c, d]$
$\self = โˆ…$truetrue
$\self = [a, b]$false$c โ‰ค a โˆง b โ‰ค d$
ยงExamples
use inari::*;
assert!(const_interval!(1.0, 2.0).subset(const_interval!(1.0, 2.0)));
assert!(Interval::EMPTY.subset(Interval::EMPTY));
assert!(Interval::EMPTY.subset(Interval::ENTIRE));
assert!(Interval::ENTIRE.subset(Interval::ENTIRE));
Sourceยง

impl Interval

Source

pub fn to_be_bytes(self) -> [u8; 16]

Returns the interchange representation of self in the big-endian byte order.

Source

pub fn to_le_bytes(self) -> [u8; 16]

Returns the interchange representation of self in the little-endian byte order.

Source

pub fn to_ne_bytes(self) -> [u8; 16]

Returns the interchange representation of self in the native byte order of the target platform.

Source

pub fn try_from_be_bytes(bytes: [u8; 16]) -> Option<Self>

Creates an Interval from its interchange representation in the big-endian byte order.

Source

pub fn try_from_le_bytes(bytes: [u8; 16]) -> Option<Self>

Creates an Interval from its interchange representation in the little-endian byte order.

Source

pub fn try_from_ne_bytes(bytes: [u8; 16]) -> Option<Self>

Creates an Interval from its interchange representation in the native byte order of the target platform.

Sourceยง

impl Interval

Source

pub const EMPTY: Self

$โˆ…$, the empty set.

Source

pub const ENTIRE: Self

$[-โˆž, +โˆž]$.

Source

pub const E: Self

The tightest interval enclosing $\e$, the base of natural logarithms.

Source

pub const FRAC_1_PI: Self

The tightest interval enclosing $1 / ฯ€$.

Source

pub const FRAC_1_SQRT_2: Self

The tightest interval enclosing $1 / \sqrt{2}$.

Source

pub const FRAC_2_PI: Self

The tightest interval enclosing $2 / ฯ€$.

Source

pub const FRAC_2_SQRT_PI: Self

The tightest interval enclosing $2 / \sqrt{ฯ€}$.

Source

pub const FRAC_PI_2: Self

The tightest interval enclosing $ฯ€ / 2$.

Source

pub const FRAC_PI_3: Self

The tightest interval enclosing $ฯ€ / 3$.

Source

pub const FRAC_PI_4: Self

The tightest interval enclosing $ฯ€ / 4$.

Source

pub const FRAC_PI_6: Self

The tightest interval enclosing $ฯ€ / 6$.

Source

pub const FRAC_PI_8: Self

The tightest interval enclosing $ฯ€ / 8$.

Source

pub const LN_10: Self

The tightest interval enclosing $\ln 10$.

Source

pub const LN_2: Self

The tightest interval enclosing $\ln 2$.

Source

pub const LOG10_2: Self

The tightest interval enclosing $\log_{10} 2$.

Source

pub const LOG10_E: Self

The tightest interval enclosing $\log_{10} \e$.

Source

pub const LOG2_10: Self

The tightest interval enclosing $\log_2 10$.

Source

pub const LOG2_E: Self

The tightest interval enclosing $\log_2 \e$.

Source

pub const PI: Self

The tightest interval enclosing $ฯ€$.

Source

pub const SQRT_2: Self

The tightest interval enclosing $\sqrt{2}$.

Source

pub const TAU: Self

The tightest interval enclosing $2 ฯ€$.

Sourceยง

impl Interval

Source

pub fn acos(self) -> Self

Returns the inverse cosine of self.

The domain and the range of the point function are:

DomainRange
$[-1, 1]$$[0, ฯ€]$
Source

pub fn acosh(self) -> Self

Returns the inverse hyperbolic cosine of self.

The domain and the range of the point function are:

DomainRange
$[1, โˆž)$$[0, โˆž)$
Source

pub fn asin(self) -> Self

Returns the inverse sine of self.

The domain and the range of the point function are:

DomainRange
$[-1, 1]$$[-ฯ€/2, ฯ€/2]$
Source

pub fn asinh(self) -> Self

Returns the inverse hyperbolic sine of self.

The domain and the range of the point function are:

DomainRange
$\R$$\R$
Source

pub fn atan(self) -> Self

Returns the inverse tangent of self.

The domain and the range of the point function are:

DomainRange
$\R$$(-ฯ€/2, ฯ€/2)$
Source

pub fn atan2(self, rhs: Self) -> Self

Returns the angle of the point $(\rhs, \self)$ measured counterclockwise from the positive $x$-axis in the Euclidean plane.

The domain and the range of the point function are:

DomainRange
$\R^2 โˆ– \set{(0, 0)}$$(-ฯ€, ฯ€]$
Source

pub fn atanh(self) -> Self

Returns the inverse hyperbolic tangent of self.

The domain and the range of the point function are:

DomainRange
$(-1, 1)$$\R$
Source

pub fn cos(self) -> Self

Returns the cosine of self.

The domain and the range of the point function are:

DomainRange
$\R$$[-1, 1]$
Source

pub fn cosh(self) -> Self

Returns the hyperbolic cosine of self.

The domain and the range of the point function are:

DomainRange
$\R$$[1, โˆž)$
Source

pub fn exp(self) -> Self

Returns self raised to the power of $\e$.

The domain and the range of the point function are:

DomainRange
$\R$$(0, โˆž)$
Source

pub fn exp10(self) -> Self

Returns self raised to the power of 10.

The domain and the range of the point function are:

DomainRange
$\R$$(0, โˆž)$
Source

pub fn exp2(self) -> Self

Returns self raised to the power of 2.

The domain and the range of the point function are:

DomainRange
$\R$$(0, โˆž)$
Source

pub fn ln(self) -> Self

Returns the natural logarithm of self.

The domain and the range of the point function are:

DomainRange
$(0, โˆž)$$\R$
Source

pub fn log10(self) -> Self

Returns the base-10 logarithm of self.

The domain and the range of the point function are:

DomainRange
$(0, โˆž)$$\R$
Source

pub fn log2(self) -> Self

Returns the base-2 logarithm of self.

The domain and the range of the point function are:

DomainRange
$(0, โˆž)$$\R$
Source

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

Returns self raised to the power of rhs.

The point function is defined as follows:

$$ x^y = \begin{cases} 0 & \for x = 0 โˆง y > 0, \\ e^{y \ln x} & \for x > 0. \end{cases} $$

The domain and the range of the point function are:

DomainRange
$((0, โˆž) ร— \R) โˆช (\set 0 ร— (0, โˆž))$$[0, โˆž)$
Source

pub fn powi(self, rhs: i32) -> Self

Returns self raised to the power of rhs.

The point functions are indexed by $n$, and are defined as follows:

$$ x^n = \begin{cases} \overbrace{x ร— โ‹ฏ ร— x}^{n \text{ copies}} & \for n > 0, \\ 1 & \for n = 0, \\ 1 / x^{-n} & \for n < 0. \end{cases} $$

The domains and the ranges of the point functions are:

DomainRange
$n > 0$, odd$\R$$\R$
$n > 0$, even$\R$$[0, โˆž)$
$n = 0$$\R$$\set 1$
$n < 0$, odd$\R โˆ– \set 0$$\R โˆ– \set 0$
$n < 0$, even$\R โˆ– \set 0$$(0, โˆž)$
Source

pub fn sin(self) -> Self

Returns the sine of self.

The domain and the range of the point function are:

DomainRange
$\R$$[-1, 1]$
Source

pub fn sinh(self) -> Self

Returns the hyperbolic sine of self.

The domain and the range of the point function are:

DomainRange
$\R$$\R$
Source

pub fn tan(self) -> Self

Returns the tangent of self.

The domain and the range of the point function are:

DomainRange
$\R โˆ– \set{(n + 1/2) ฯ€ โˆฃ n โˆˆ \Z}$$\R$
Source

pub fn tanh(self) -> Self

Returns the hyperbolic tangent of self.

The domain and the range of the point function are:

DomainRange
$\R$$(-1, 1)$
Sourceยง

impl Interval

Source

pub fn ceil(self) -> Self

Rounds self to the closest integer toward $+โˆž$.

The domain and the range of the point function are:

DomainRange
$\R$$\Z$
ยงExamples
use inari::*;
assert_eq!(const_interval!(0.2, 1.2).ceil(), const_interval!(1.0, 2.0));
assert_eq!(const_interval!(0.8, 1.8).ceil(), const_interval!(1.0, 2.0));
assert_eq!(const_interval!(-1.2, -0.2).ceil(), const_interval!(-1.0, 0.0));
assert_eq!(const_interval!(-1.8, -0.8).ceil(), const_interval!(-1.0, 0.0));
assert_eq!(Interval::EMPTY.ceil(), Interval::EMPTY);
assert_eq!(Interval::ENTIRE.ceil(), Interval::ENTIRE);

See also: Interval::floor, Interval::trunc.

Source

pub fn floor(self) -> Self

Rounds self to the closest integer toward $-โˆž$.

The domain and the range of the point function are:

DomainRange
$\R$$\Z$
ยงExamples
use inari::*;
assert_eq!(const_interval!(0.2, 1.2).floor(), const_interval!(0.0, 1.0));
assert_eq!(const_interval!(0.8, 1.8).floor(), const_interval!(0.0, 1.0));
assert_eq!(const_interval!(-1.2, -0.2).floor(), const_interval!(-2.0, -1.0));
assert_eq!(const_interval!(-1.8, -0.8).floor(), const_interval!(-2.0, -1.0));
assert_eq!(Interval::EMPTY.floor(), Interval::EMPTY);
assert_eq!(Interval::ENTIRE.floor(), Interval::ENTIRE);

See also: Interval::ceil, Interval::trunc.

Source

pub fn round(self) -> Self

Rounds self to the closest integer, away from zero in case of ties.

The domain and the range of the point function are:

DomainRange
$\R$$\Z$
ยงExamples
use inari::*;
assert_eq!(const_interval!(0.2, 1.2).round(), const_interval!(0.0, 1.0));
assert_eq!(const_interval!(0.5, 1.5).round(), const_interval!(1.0, 2.0));
assert_eq!(const_interval!(0.8, 1.8).round(), const_interval!(1.0, 2.0));
assert_eq!(const_interval!(-1.2, -0.2).round(), const_interval!(-1.0, 0.0));
assert_eq!(const_interval!(-1.5, -0.5).round(), const_interval!(-2.0, -1.0));
assert_eq!(const_interval!(-1.8, -0.8).round(), const_interval!(-2.0, -1.0));
assert_eq!(Interval::EMPTY.round(), Interval::EMPTY);
assert_eq!(Interval::ENTIRE.round(), Interval::ENTIRE);

See also: Interval::round_ties_even.

Source

pub fn round_ties_even(self) -> Self

Rounds self to the closest integer, the even number in case of ties.

The domain and the range of the point function are:

DomainRange
$\R$$\Z$
ยงExamples
use inari::*;
assert_eq!(const_interval!(0.2, 1.2).round_ties_even(), const_interval!(0.0, 1.0));
assert_eq!(const_interval!(0.5, 1.5).round_ties_even(), const_interval!(0.0, 2.0));
assert_eq!(const_interval!(0.8, 1.8).round_ties_even(), const_interval!(1.0, 2.0));
assert_eq!(const_interval!(-1.2, -0.2).round_ties_even(), const_interval!(-1.0, 0.0));
assert_eq!(const_interval!(-1.5, -0.5).round_ties_even(), const_interval!(-2.0, 0.0));
assert_eq!(const_interval!(-1.8, -0.8).round_ties_even(), const_interval!(-2.0, -1.0));
assert_eq!(Interval::EMPTY.round_ties_even(), Interval::EMPTY);
assert_eq!(Interval::ENTIRE.round_ties_even(), Interval::ENTIRE);

See also: Interval::round.

Source

pub fn sign(self) -> Self

Returns the sign of self.

The domain and the range of the point function are:

DomainRange
$\R$$\set{-1, 0, 1}$

Note the difference in definition between f64::signum and this function; +0.0_f64.signum() and -0.0_f64.signum() return +1.0 and -1.0, respectively, while the sign of zero is just zero.

ยงExamples
use inari::*;
assert_eq!(const_interval!(-10.0, -0.1).sign(), const_interval!(-1.0, -1.0));
assert_eq!(const_interval!(0.0, 0.0).sign(), const_interval!(0.0, 0.0));
assert_eq!(const_interval!(0.1, 10.0).sign(), const_interval!(1.0, 1.0));
assert_eq!(Interval::EMPTY.sign(), Interval::EMPTY);
assert_eq!(Interval::ENTIRE.sign(), const_interval!(-1.0, 1.0));
Source

pub fn trunc(self) -> Self

Rounds self to the closest integer toward zero.

The domain and the range of the point function are:

DomainRange
$\R$$\Z$
ยงExamples
use inari::*;
assert_eq!(const_interval!(0.2, 1.2).trunc(), const_interval!(0.0, 1.0));
assert_eq!(const_interval!(0.8, 1.8).trunc(), const_interval!(0.0, 1.0));
assert_eq!(const_interval!(-1.2, -0.2).trunc(), const_interval!(-1.0, 0.0));
assert_eq!(const_interval!(-1.8, -0.8).trunc(), const_interval!(-1.0, 0.0));
assert_eq!(Interval::EMPTY.trunc(), Interval::EMPTY);
assert_eq!(Interval::ENTIRE.trunc(), Interval::ENTIRE);

See also: Interval::ceil, Interval::floor.

Sourceยง

impl Interval

Source

pub fn inf(self) -> f64

Returns the lower bound of self.

The lower bound of an interval $๐’™$ is:

$$ \inf(๐’™) = \begin{cases} +โˆž & \if ๐’™ = โˆ…, \\ a & \if ๐’™ = [a, b]. \end{cases} $$

The exact value is returned. When $a = 0$, -0.0 is returned.

ยงExamples
use inari::*;
assert_eq!(const_interval!(-2.0, 3.0).inf(), -2.0);
assert_eq!(Interval::EMPTY.inf(), f64::INFINITY);
assert_eq!(Interval::ENTIRE.inf(), f64::NEG_INFINITY);

See also: Interval::sup.

Source

pub fn mag(self) -> f64

Returns the magnitude of self if it is nonempty; otherwise, a NaN.

The magnitude of a nonempty interval $๐’™ = [a, b]$ is:

$$ \begin{align*} \mag(๐’™) &= \sup \set{|x| โˆฃ x โˆˆ ๐’™} \\ &= \max \set{|a|, |b|}. \end{align*} $$

The exact value is returned.

ยงExamples
use inari::*;
assert_eq!(const_interval!(-2.0, 3.0).mag(), 3.0);
assert!(Interval::EMPTY.mag().is_nan());
assert_eq!(Interval::ENTIRE.mag(), f64::INFINITY);

See also: Interval::mig.

Source

pub fn mid(self) -> f64

Returns the midpoint of self if it is nonempty; otherwise, a NaN.

The midpoint of a nonempty interval $๐’™ = [a, b]$ is:

$$ \mid(๐’™) = \frac{a + b}{2}. $$

As an approximation in f64, it returns:

  • 0.0, if $\self = [-โˆž, +โˆž]$;
  • f64::MIN, if $\self = [-โˆž, b]$, where $b โˆˆ \R$;
  • f64::MAX, if $\self = [a, +โˆž]$, where $a โˆˆ \R$;
  • otherwise, the closest f64 number to $\mid(\self)$, away from zero in case of ties.
ยงExamples
use inari::*;
assert_eq!(const_interval!(-2.0, 3.0).mid(), 0.5);
assert_eq!(const_interval!(f64::NEG_INFINITY, 3.0).mid(), f64::MIN);
assert_eq!(const_interval!(-2.0, f64::INFINITY).mid(), f64::MAX);
assert!(Interval::EMPTY.mid().is_nan());
assert_eq!(Interval::ENTIRE.mid(), 0.0);

See also: Interval::rad.

Source

pub fn mig(self) -> f64

Returns the mignitude of self if it is nonempty; otherwise, a NaN.

The mignitude of a nonempty interval $๐’™ = [a, b]$ is:

$$ \begin{align*} \mig(๐’™) &= \inf \set{|x| โˆฃ x โˆˆ ๐’™} \\ &= \begin{cases} \min \set{|a|, |b|} & \if \sgn(a) = \sgn(b), \\ 0 & \otherwise. \end{cases} \end{align*} $$

The exact value is returned.

ยงExamples
use inari::*;
assert_eq!(const_interval!(-2.0, 3.0).mig(), 0.0);
assert_eq!(const_interval!(2.0, 3.0).mig(), 2.0);
assert!(Interval::EMPTY.mig().is_nan());
assert_eq!(Interval::ENTIRE.mig(), 0.0);

See also: Interval::mag.

Source

pub fn rad(self) -> f64

Returns the radius of self if it is nonempty; otherwise, a NaN.

The radius of a nonempty interval $๐’™ = [a, b]$ is:

$$ \rad(๐’™) = \frac{b - a}{2}. $$

As an approximation in f64, it returns the least f64 number r that satisfies $\self โІ [๐š– - ๐š›, ๐š– + ๐š›]$, where m is the midpoint returned by Self::mid.

ยงExamples
use inari::*;
assert_eq!(const_interval!(-2.0, 3.0).rad(), 2.5);
assert!(Interval::EMPTY.rad().is_nan());
assert_eq!(Interval::ENTIRE.rad(), f64::INFINITY);

See also: Interval::mid.

Source

pub fn sup(self) -> f64

Returns the upper bound of self.

The upper bound of an interval $๐’™$ is:

$$ \sup(๐’™) = \begin{cases} -โˆž & \if ๐’™ = โˆ…, \\ b & \if ๐’™ = [a, b]. \end{cases} $$

The exact value is returned. When $b = 0$, 0.0 (the positive zero) is returned.

ยงExamples
use inari::*;
assert_eq!(const_interval!(-2.0, 3.0).sup(), 3.0);
assert_eq!(Interval::EMPTY.sup(), f64::NEG_INFINITY);
assert_eq!(Interval::ENTIRE.sup(), f64::INFINITY);

See also: Interval::inf.

Source

pub fn wid(self) -> f64

Returns the width of self if it is nonempty; otherwise, a NaN.

The width of a nonempty interval $๐’™ = [a, b]$ is:

$$ \wid(๐’™) = b - a. $$

As an approximation in f64, it returns the closest f64 number toward $+โˆž$.

ยงExamples
use inari::*;
assert_eq!(const_interval!(-2.0, 3.0).wid(), 5.0);
assert_eq!(const_interval!(-1.0, f64::MAX).wid(), f64::INFINITY);
assert!(Interval::EMPTY.wid().is_nan());
assert_eq!(Interval::ENTIRE.wid(), f64::INFINITY);
Sourceยง

impl Interval

Source

pub fn overlap(self, rhs: Self) -> Overlap

Returns the overlapping state of self and rhs. See Overlap for the possible states to be returned.

Sourceยง

impl Interval

Source

pub fn convex_hull(self, rhs: Self) -> Self

Returns $\hull(\self โˆช \rhs)$, the tightest interval that contains both self and rhs as its subsets.

$\rhs = โˆ…$$\rhs = [c, d]$
$\self = โˆ…$$โˆ…$$[c, d]$
$\self = [a, b]$$[a, b]$$[\min \set{a, c}, \max \set{b, d}]$
Source

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

Returns $\self โˆฉ \rhs$, the intersection of self and rhs.

$\rhs = โˆ…$$\rhs = [c, d]$
$\self = โˆ…$$โˆ…$$โˆ…$
$\self = [a, b]$$โˆ…$$[\max \set{a, c}, \min \set{b, d}]$

Trait Implementationsยง

Sourceยง

impl Add for Interval

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 Interval

Sourceยง

type Output = <Interval as Add>::Output

The resulting type after applying the + operator.
Sourceยง

fn add(self, other: &Interval) -> <Interval as Add<Interval>>::Output

Performs the + operation. Read more
Sourceยง

impl Add<&Interval> for &Interval

Sourceยง

type Output = <Interval as Add>::Output

The resulting type after applying the + operator.
Sourceยง

fn add(self, other: &Interval) -> <Interval as Add<Interval>>::Output

Performs the + operation. Read more
Sourceยง

impl<'a> Add<Interval> for &'a Interval

Sourceยง

type Output = <Interval as Add>::Output

The resulting type after applying the + operator.
Sourceยง

fn add(self, other: Interval) -> <Interval as Add<Interval>>::Output

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<&Interval> for Interval

Sourceยง

fn add_assign(&mut self, other: &Interval)

Performs the += operation. Read more
Sourceยง

impl Clone for Interval

Sourceยง

fn clone(&self) -> Interval

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

Sourceยง

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

Formats the value using the given formatter. Read more
Sourceยง

impl Div for Interval

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 Interval

Sourceยง

type Output = <Interval as Div>::Output

The resulting type after applying the / operator.
Sourceยง

fn div(self, other: &Interval) -> <Interval as Div<Interval>>::Output

Performs the / operation. Read more
Sourceยง

impl Div<&Interval> for &Interval

Sourceยง

type Output = <Interval as Div>::Output

The resulting type after applying the / operator.
Sourceยง

fn div(self, other: &Interval) -> <Interval as Div<Interval>>::Output

Performs the / operation. Read more
Sourceยง

impl<'a> Div<Interval> for &'a Interval

Sourceยง

type Output = <Interval as Div>::Output

The resulting type after applying the / operator.
Sourceยง

fn div(self, other: Interval) -> <Interval as Div<Interval>>::Output

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<&Interval> for Interval

Sourceยง

fn div_assign(&mut self, other: &Interval)

Performs the /= operation. Read more
Sourceยง

impl Eq for Interval

Sourceยง

impl FromStr for Interval

Sourceยง

type Err = IntervalError

The associated error which can be returned from parsing.
Sourceยง

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

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

impl Hash for Interval

Sourceยง

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 ยท Sourceยง

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Sourceยง

impl LowerExp for Interval

Sourceยง

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

Formats the value using the given formatter. Read more
Sourceยง

impl LowerHex for Interval

Sourceยง

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

Formats the value using the given formatter. Read more
Sourceยง

impl Mul for Interval

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 Interval

Sourceยง

type Output = <Interval as Mul>::Output

The resulting type after applying the * operator.
Sourceยง

fn mul(self, other: &Interval) -> <Interval as Mul<Interval>>::Output

Performs the * operation. Read more
Sourceยง

impl Mul<&Interval> for &Interval

Sourceยง

type Output = <Interval as Mul>::Output

The resulting type after applying the * operator.
Sourceยง

fn mul(self, other: &Interval) -> <Interval as Mul<Interval>>::Output

Performs the * operation. Read more
Sourceยง

impl<'a> Mul<Interval> for &'a Interval

Sourceยง

type Output = <Interval as Mul>::Output

The resulting type after applying the * operator.
Sourceยง

fn mul(self, other: Interval) -> <Interval as Mul<Interval>>::Output

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<&Interval> for Interval

Sourceยง

fn mul_assign(&mut self, other: &Interval)

Performs the *= operation. Read more
Sourceยง

impl Neg for Interval

Sourceยง

type Output = Interval

The resulting type after applying the - operator.
Sourceยง

fn neg(self) -> Self

Performs the unary - operation. Read more
Sourceยง

impl Neg for &Interval

Sourceยง

type Output = <Interval as Neg>::Output

The resulting type after applying the - operator.
Sourceยง

fn neg(self) -> <Interval as Neg>::Output

Performs the unary - operation. Read more
Sourceยง

impl PartialEq for Interval

Sourceยง

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) ยท 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 Send for Interval

Sourceยง

impl Sub for Interval

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 Interval

Sourceยง

type Output = <Interval as Sub>::Output

The resulting type after applying the - operator.
Sourceยง

fn sub(self, other: &Interval) -> <Interval as Sub<Interval>>::Output

Performs the - operation. Read more
Sourceยง

impl Sub<&Interval> for &Interval

Sourceยง

type Output = <Interval as Sub>::Output

The resulting type after applying the - operator.
Sourceยง

fn sub(self, other: &Interval) -> <Interval as Sub<Interval>>::Output

Performs the - operation. Read more
Sourceยง

impl<'a> Sub<Interval> for &'a Interval

Sourceยง

type Output = <Interval as Sub>::Output

The resulting type after applying the - operator.
Sourceยง

fn sub(self, other: Interval) -> <Interval as Sub<Interval>>::Output

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<&Interval> for Interval

Sourceยง

fn sub_assign(&mut self, other: &Interval)

Performs the -= operation. Read more
Sourceยง

impl Sync for Interval

Sourceยง

impl TryFrom<(f64, f64)> for Interval

Sourceยง

type Error = IntervalError

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

fn try_from((a, b): (f64, f64)) -> Result<Self>

Performs the conversion.
Sourceยง

impl Unpin for Interval

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> Az for T

Sourceยง

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
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<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Sourceยง

fn cast_from(src: Src) -> Dst

Casts the value.
Sourceยง

impl<T> CheckedAs for T

Sourceยง

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Sourceยง

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Sourceยง

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
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> OverflowingAs for T

Sourceยง

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Sourceยง

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Sourceยง

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Sourceยง

impl<T> SaturatingAs for T

Sourceยง

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Sourceยง

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Sourceยง

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
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.
Sourceยง

impl<T> UnwrappedAs for T

Sourceยง

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Sourceยง

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Sourceยง

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Sourceยง

impl<T> WrappingAs for T

Sourceยง

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Sourceยง

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Sourceยง

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.