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: f64Implementations§
Source§impl Interval
impl Interval
Sourcefn raw(lo: f64, hi: f64) -> Self
fn raw(lo: f64, hi: f64) -> Self
The interval of the pair, which the caller proved well-formed.
Sourcepub fn point(x: f64) -> Self
pub fn point(x: f64) -> Self
[x, x]. Panics on NaN — and on ±∞, which is not a real number
(it would violate (I2)).
Sourcepub fn mid_rad(m: f64, r: f64) -> Self
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.
Sourcepub fn enclose(x: DoubleDouble) -> Self
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).
Sourcepub fn mid(self) -> f64
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.
Sourcepub fn mag(self) -> f64
pub fn mag(self) -> f64
max{|x| : x ∈ X}, the magnitude (exact; +∞ when unbounded, NaN
when empty).
Sourcepub fn contains(self, x: f64) -> bool
pub fn contains(self, x: f64) -> bool
x ∈ X (false for a NaN or infinite x: the elements are real
numbers).
Sourcepub fn is_subset_of(self, other: Self) -> bool
pub fn is_subset_of(self, other: Self) -> bool
X ⊆ Y (∅ is a subset of every interval).
Sourcepub fn certainly_le(self, b: f64) -> bool
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).
Sourcepub fn certainly_ge(self, a: f64) -> bool
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.
Sourcepub fn certainly_within(self, t: f64) -> bool
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.
Sourcepub fn intersection(self, other: Self) -> Self
pub fn intersection(self, other: Self) -> Self
The intersection (possibly Interval::EMPTY).
Sourcepub fn sqrt(self) -> Self
pub fn sqrt(self) -> Self
{√x : x ∈ X, x ≥ 0} (Interval::EMPTY when sup < 0).
Trait Implementations§
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.
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§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.
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§impl AddAssign for Interval
impl AddAssign for Interval
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+= operation. Read moreSource§impl AddAssign<f64> for Interval
impl AddAssign<f64> for Interval
Source§fn add_assign(&mut self, rhs: f64)
fn add_assign(&mut self, rhs: f64)
+= operation. Read moreimpl Copy for Interval
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.
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§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].)
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§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.
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§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.
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§impl DivAssign for Interval
impl DivAssign for Interval
Source§fn div_assign(&mut self, rhs: Self)
fn div_assign(&mut self, rhs: Self)
/= operation. Read moreSource§impl DivAssign<f64> for Interval
impl DivAssign<f64> for Interval
Source§fn div_assign(&mut self, rhs: f64)
fn div_assign(&mut self, rhs: f64)
/= operation. Read moreSource§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.
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§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).
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§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.
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§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.
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§impl MulAssign for Interval
impl MulAssign for Interval
Source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
*= operation. Read moreSource§impl MulAssign<f64> for Interval
impl MulAssign<f64> for Interval
Source§fn mul_assign(&mut self, rhs: f64)
fn mul_assign(&mut self, rhs: f64)
*= operation. Read moreimpl StructuralPartialEq for Interval
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.
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§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.
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.