Struct inari::Interval

source Β· []
#[repr(C)]
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

Returns the absolute value of self.

The domain and the range of the point function are:

DomainRange
$\R$$[0, ∞)$

Returns the maximum of self and rhs.

The domain and the range of the point function are:

DomainRange
$\R^2$$\R$

Returns the minimum of self and rhs.

The domain and the range of the point function are:

DomainRange
$\R^2$$\R$

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);

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

See Interval::cancel_minus for more information.

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

The domain and the range of the point function are:

DomainRange
$\R^3$$\R$

Returns the multiplicative inverse of self.

The domain and the range of the point function are:

DomainRange
$\R βˆ– \set 0$$\R βˆ– \set 0$

Returns the square of self.

The domain and the range of the point function are:

DomainRange
$\R$$[0, ∞)$

Returns the principal square root of self.

The domain and the range of the point function are:

DomainRange
$[0, ∞)$$[0, ∞)$

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));

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));

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));

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());

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());

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());

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());

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));

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));

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));

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$

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));

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

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

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

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

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

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

$βˆ…$, the empty set.

$[-∞, +∞]$.

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

The tightest interval enclosing $1 / Ο€$.

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

The tightest interval enclosing $2 / Ο€$.

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

The tightest interval enclosing $Ο€ / 2$.

The tightest interval enclosing $Ο€ / 3$.

The tightest interval enclosing $Ο€ / 4$.

The tightest interval enclosing $Ο€ / 6$.

The tightest interval enclosing $Ο€ / 8$.

The tightest interval enclosing $\ln 10$.

The tightest interval enclosing $\ln 2$.

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

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

The tightest interval enclosing $\log_2 10$.

The tightest interval enclosing $\log_2 \e$.

The tightest interval enclosing $Ο€$.

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

The tightest interval enclosing $2 Ο€$.

Returns the inverse cosine of self.

The domain and the range of the point function are:

DomainRange
$[-1, 1]$$[0, Ο€]$

Returns the inverse hyperbolic cosine of self.

The domain and the range of the point function are:

DomainRange
$[1, ∞)$$[0, ∞)$

Returns the inverse sine of self.

The domain and the range of the point function are:

DomainRange
$[-1, 1]$$[-Ο€/2, Ο€/2]$

Returns the inverse hyperbolic sine of self.

The domain and the range of the point function are:

DomainRange
$\R$$\R$

Returns the inverse tangent of self.

The domain and the range of the point function are:

DomainRange
$\R$$(-Ο€/2, Ο€/2)$

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)}$$(-Ο€, Ο€]$

Returns the inverse hyperbolic tangent of self.

The domain and the range of the point function are:

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

Returns the cosine of self.

The domain and the range of the point function are:

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

Returns the hyperbolic cosine of self.

The domain and the range of the point function are:

DomainRange
$\R$$[1, ∞)$

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

The domain and the range of the point function are:

DomainRange
$\R$$(0, ∞)$

Returns self raised to the power of 10.

The domain and the range of the point function are:

DomainRange
$\R$$(0, ∞)$

Returns self raised to the power of 2.

The domain and the range of the point function are:

DomainRange
$\R$$(0, ∞)$

Returns the natural logarithm of self.

The domain and the range of the point function are:

DomainRange
$(0, ∞)$$\R$

Returns the base-10 logarithm of self.

The domain and the range of the point function are:

DomainRange
$(0, ∞)$$\R$

Returns the base-2 logarithm of self.

The domain and the range of the point function are:

DomainRange
$(0, ∞)$$\R$

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, ∞)$

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, ∞)$

Returns the sine of self.

The domain and the range of the point function are:

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

Returns the hyperbolic sine of self.

The domain and the range of the point function are:

DomainRange
$\R$$\R$

Returns the tangent of self.

The domain and the range of the point function are:

DomainRange
$\R βˆ– \set{(n + 1/2) Ο€ ∣ n ∈ \Z}$$\R$

Returns the hyperbolic tangent of self.

The domain and the range of the point function are:

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

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.

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.

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_to_even.

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_to_even(), const_interval!(0.0, 1.0));
assert_eq!(const_interval!(0.5, 1.5).round_ties_to_even(), const_interval!(0.0, 2.0));
assert_eq!(const_interval!(0.8, 1.8).round_ties_to_even(), const_interval!(1.0, 2.0));
assert_eq!(const_interval!(-1.2, -0.2).round_ties_to_even(), const_interval!(-1.0, 0.0));
assert_eq!(const_interval!(-1.5, -0.5).round_ties_to_even(), const_interval!(-2.0, 0.0));
assert_eq!(const_interval!(-1.8, -0.8).round_ties_to_even(), const_interval!(-2.0, -1.0));
assert_eq!(Interval::EMPTY.round_ties_to_even(), Interval::EMPTY);
assert_eq!(Interval::ENTIRE.round_ties_to_even(), Interval::ENTIRE);

See also: Interval::round.

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));

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.

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.

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.

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.

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.

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.

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.

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);

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

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}]$

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

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

Performs the += operation. Read more

Performs the += operation. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

Performs the /= operation. Read more

Performs the /= operation. Read more

The associated error which can be returned from parsing.

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

Feeds this value into the given Hasher. Read more

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

Formats the value using the given formatter.

Formats the value using the given formatter.

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

Performs the *= operation. Read more

Performs the *= operation. Read more

The resulting type after applying the - operator.

Performs the unary - operation. Read more

The resulting type after applying the - operator.

Performs the unary - operation. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

Performs the -= operation. Read more

Performs the -= operation. Read more

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Casts the value.

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Casts the value.

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Casts the value.

Casts the value.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Casts the value.

Casts the value.