interval API

Purpose

interval is interval arithmetic over Binary endpoints. An Interval is a closed real interval [x‾,x‾][\underline{x}, \overline{x}], possibly unbounded, or the empty set; every operation returns an interval that contains all exact results of the operation on points of its operands (the inclusion property). DecoratedInterval adds the decorations of IEEE 1788-2015, IntervalContext rounds results into a target binary format and reports IntervalFlags.

Despite the name, the stored representation is the endpoint pair, not a midpoint and a radius: Interval::from_midpoint_radius(center, radius) builds an interval from the midpoint–radius view, and midpoint() and radius() read it back as IEEE 1788-2015 12.12.8 defines them. The tutorial shows typical use; the design page derives the formulas and proves the inclusion property. The fallible pipeline wrapper is interval_checked.

Conventions used on this page:

  • RD⁡p\operatorname{RD}_p and RU⁡p\operatorname{RU}_p round toward −∞-\infty and +∞+\infty to pp significant bits. “Rounded outward” means the lower endpoint is rounded with RD⁡p\operatorname{RD}_p and the upper with RU⁡p\operatorname{RU}_p.
  • The precision of an interval is a tag in bits. Operations round their result outward to the larger precision of their operands; elementary functions use the precision of their argument.
  • The exponent range of Binary endpoints is the implementation range of binary: leading-bit exponents up to emax⁡=230−1e_{\max} = 2^{30} - 1, and nonzero magnitudes down to 2emin⁡−p+12^{e_{\min} - p + 1} with emin⁡=1−emax⁡=−(230−2)e_{\min} = 1 - e_{\max} = -(2^{30} - 2). Use an IntervalContext to impose a narrower range.
  • The precision of an interval is between 1 and binary_precision_max (268,435,456) bits, the limits of a BinaryContext. A constructor that returns a value aborts on a precision outside them and names the limits; the try_ constructors and the checked tier return an error. A precision is never replaced silently (before 0.12 a precision below 1 became 1).
  • Empty is the empty set, Entire is (−∞,+∞)(-\infty, +\infty). An unbounded interval stores −∞-\infty and/or +∞+\infty as endpoints; these mean that the set is unbounded on that side, never that it contains an infinite value.
  • The few inputs for which the code currently loses part of the input set, widens without need, or rounds or flags a context result incorrectly are noted where they occur, with their tracking issue, and collected under Known limitations on the design page.

Importing

Add the package and the endpoint package to your moon.pkg:

import {
  "Luna-Flow/floating/binary",
  "Luna-Flow/floating/interval",
  "Luna-Flow/arithmetic" @lf_arith,
}

The examples refer to the packages as @interval., @binary. and @lf_arith. (for Luna-Flow/arithmetic, which defines ArithmeticError, RoundingMode and the enclosure traits). They use two helpers: iv(lo, hi) builds the 53-bit interval with integer endpoints, and fmt(x) prints the endpoints as six-digit decimals, the lower one rounded down and the upper one rounded up, so the text still encloses the stored set.

///|
fn iv(lo : Int, hi : Int) -> @interval.Interval {
  @interval.Interval::from_bounds(
    @binary.Binary::from_int(lo, precision=53),
    @binary.Binary::from_int(hi, precision=53),
  )
}

///|
fn fmt(x : @interval.Interval) -> String {
  if x.is_empty() {
    return "[empty]"
  }
  let down = @binary.BinaryContext::new(
    precision=53,
    rounding=@binary.BinaryRoundingMode::RoundTowardNegative,
  )
  let up = @binary.BinaryContext::new(
    precision=53,
    rounding=@binary.BinaryRoundingMode::RoundTowardPositive,
  )
  "[" +
  x.lower_bound().to_decimal_string_ctx(6, down).0 +
  ", " +
  x.upper_bound().to_decimal_string_ctx(6, up).0 +
  "]"
}

Types

Interval

Interval is a closed interval with Binary endpoints and a precision tag.

pub struct Interval {
  // private fields
} derive(Eq, @debug.Debug)

A non-empty value satisfies x‾≤x‾\underline{x} \le \overline{x}, has no NaN endpoint, never has x‾=+∞\underline{x} = +\infty or x‾=−∞\overline{x} = -\infty, and has precision ≥1\ge 1. The empty set is a separate state. The fields are private; construct values with the functions in Construction. == is the equal of IEEE 1788-2015 Table 10.3: it compares the sets, not the representation; see Interval::equal and Interval::identical.

DecoratedInterval

DecoratedInterval is an Interval paired with an IEEE 1788 Decoration, or the special value NaI (not an interval).

pub struct DecoratedInterval {
  // private fields
} derive(Eq)

The decoration is kept canonical: an empty interval always carries Trv, an unbounded interval never carries Com, and only DecoratedInterval::nai carries Ill.

Decoration

Decoration is the IEEE 1788 decoration of a decorated interval, ordered Ill < Trv < Def < Dac < Com.

pub(all) enum Decoration {
  Ill
  Trv
  Def
  Dac
  Com
} derive(Compare, Eq, @debug.Debug)

For a decorated result (y,d)(\boldsymbol{y}, d) of a function ff evaluated on a box x\boldsymbol{x}:

ConstructorMeaning
Comx\boldsymbol{x} is non-empty and bounded, ff is defined and continuous on x\boldsymbol{x}, and y\boldsymbol{y} is bounded
Dacx\boldsymbol{x} is non-empty, ff is defined on x\boldsymbol{x} and its restriction to x\boldsymbol{x} is continuous
Defx\boldsymbol{x} is non-empty and ff is defined on x\boldsymbol{x}
Trvnothing is known
Illthe value is NaI

Each property implies the ones below it, which is why the decorations are totally ordered; Decoration derives Compare in that order, so <, <=, > and >= are the comparisons of decorations of IEEE 1788-2015 11.5.3. Show prints the lower-case IEEE 1788 names com, dac, def, trv, ill.

OverlapState

OverlapState is the result of overlap: the IEEE 1788 classification of the relative position of two intervals.

#derive(Eq, @debug.Debug)
pub(all) enum OverlapState {
  BothEmpty
  FirstEmpty
  SecondEmpty
  Before
  Meets
  Overlaps
  Starts
  ContainedBy
  Finishes
  Equals
  After
  MetBy
  OverlappedBy
  StartedBy
  Contains
  FinishedBy
}

The constructors are the 16 states of IEEE 1788-2015 Table 10.7 (10.6.4), with the standard’s names: bothEmpty, firstEmpty, secondEmpty, before, meets, overlaps, starts, containedBy, finishes, equals, after, metBy, overlappedBy, startedBy, contains and finishedBy. There is no 17th state: the decorated overlap has no value for NaI (11.7.2) and returns None.

IntervalContext

IntervalContext describes a target binary format of IEEE 754-2019 3.3: a precision in bits and the exponent range [1−emax⁡,emax⁡][1 - e_{\max}, e_{\max}] (e_min is derived, not a parameter).

pub struct IntervalContext {
  // private fields
}

emin⁡e_{\min} and emax⁡e_{\max} follow IEEE 754: a finite nonzero value vv with 2e≤∣v∣<2e+12^{e} \le |v| < 2^{e+1} is in range when e≤emax⁡e \le e_{\max}, and it is normal when e≥emin⁡e \ge e_{\min}. See Contexts and flags.

IntervalFlags

IntervalFlags records the conditions raised while rounding an interval into an IntervalContext.

pub struct IntervalFlags {
  // private fields
} derive(Eq)

inexact is set when an endpoint (or, for midpoint_ctx, the midpoint) changed; overflow when it was beyond emax⁡e_{\max}; underflow when it is tiny and inexact, as IEEE 754 defines it (see Interval::apply_ctx). The fields are private; each flag is read with the accessor method of the same name, listed under IntervalFlags::new.

Construction

Interval::from_midpoint_radius

Interval::from_midpoint_radius builds the hull in the format of pp bits of the interval [c−r,c+r][c - r, c + r] from a center and a radius (IEEE 1788-2015 12.12.7). Interval::try_from_midpoint_radius returns the same interval, or an ArithmeticError where from_midpoint_radius aborts.

pub fn Interval::from_midpoint_radius(@binary.Binary, @binary.Binary, precision? : Int) -> Self
pub fn Interval::try_from_midpoint_radius(@binary.Binary, @binary.Binary, precision? : Int) -> Result[Self, @arithmetic.ArithmeticError]

The default precision is the larger of the precisions of center and radius. With pp that precision, the stored interval is

[RD⁡p(c−r),  RU⁡p(c+r)],[\operatorname{RD}_p(c - r),\; \operatorname{RU}_p(c + r)],

the exact c−rc - r rounded down and the exact c+rc + r rounded up, once each, in the exponent range of the library: both ends are numbers of the format and the interval is the tightest one of the format that contains [c−r,c+r][c - r, c + r] (see the design page). from_midpoint_radius aborts, and try_from_midpoint_radius returns a domain error, when center or radius is not finite or when radius is negative, and when precision is outside 1..=binary_precision_max.

When cc already has at most pp bits and r=0r = 0, the result is the singleton {c}\{c\}.

Interval::from_string and DecoratedInterval::from_string

IEEE 1788-2015 textToInterval (10.5.8, 12.12.7, 13.2): the interval literal s, as the hull of its value at precision bits.

pub let interval_literal_max_length : Int
pub fn Interval::from_string(String, precision? : Int) -> Result[Self, @arithmetic.ArithmeticError]
pub fn DecoratedInterval::from_string(String, precision? : Int) -> Result[Self, @arithmetic.ArithmeticError]

The portable literals of 12.11 are accepted, with the case ignored and no whitespace except the spaces and tabs the grammar allows inside the brackets:

FormExamples
number literals3.56, 1.e-3, -0x1.3p-1, 2/3, inf, -Infinity
inf-sup[1.5, 2.5], [-Inf, 2/3], [0x1.3p-1,] (the omitted bound is infinite), [,] (Entire)
point[3.56]
uncertain m?rve3.56?1 ([3.55,3.57][3.55, 3.57]), 3.56?1e2 ([355,357][355, 357]), 3.560?2u, -10? (half an ulp), -10??u ([−10,+∞][-10, +\infty]), -10?? (Entire)
special[], [empty], [entire]
decorated[1,2]_com, 3.56?1_def, [nai]

The bounds are parsed exactly (the decimal, hexadecimal and rational value, the ulp of the last place of an uncertain form) and rounded outward: the lower bound down and the upper bound up. The comparison l≤ul \le u is decided from the exact values, so a literal is never rejected or emptied by rounding; a decimal exponent or a binary exponent beyond the range is decided from the exponent and the digits without forming the value (a lower bound above the range is the largest finite float and an upper bound is +∞+\infty; below the smallest stored value they are 0 and the smallest positive stored value). Only two finite bounds of different radices that are equal to the working size and have an exponent beyond 65,536 cannot be ordered; then (12.12.7 case (b), PossiblyUndefinedOperation) the result contains both bounds.

Err is the failed call of the standard (the result Empty for a bare literal, NaI for a decorated one, and the exception UndefinedOperation). It is an ArithmeticError of the parse kind whose message names the rule that was broken (for example “the lower bound is greater than the upper bound (l <= u is required)”, “rational literal: the denominator must be a positive natural number”, “the decoration com needs a bounded interval (11.4)”). A decoration or [nai] in a bare literal is such a failure for Interval::from_string. DecoratedInterval::from_string accepts a bare literal (decorated by newDec, so com for a bounded interval and dac otherwise), bare_dec, and [nai], which is Ok(NaI); a decoration not permitted for the value (11.4: only trv for Empty, com only for a bounded interval) is an Err, and com becomes dac if the rounding of a bounded literal overflowed. A string longer than interval_literal_max_length (65,536 characters) is not parsed: 12.11.5 allows an implementation to “restrict support of some input strings (too long strings or strings with a rational number literal)” and then requires that the constructor “shall always return a Level 2 interval (possibly Entire in this case) that contains the Level 1 interval”, so the result is Entire (decorated: dac, or the trv or def the string ends with).

///|
test "from_string" {
  // 3.56?1 is [3.55, 3.57]: each bound is rounded outward
  let u = @interval.Interval::from_string("3.56?1").unwrap()
  assert_true(u.lower_bound().compare(@binary.Binary::from_double(3.55)) <= 0)
  // [0x1.3p-1,] is [19/32, +inf), exact
  let r = @interval.Interval::from_string("[0x1.3p-1,]").unwrap()
  assert_true(r.lower_bound().compare(@binary.Binary::from_double(19.0 / 32.0)) == 0)
  // the failed call is an Err that names the rule
  assert_true(@interval.Interval::from_string("[2,1]") is Err(_))
  // [nai] is NaI for the decorated form
  assert_true(@interval.DecoratedInterval::from_string("[nai]").unwrap().is_nai())
}

Interval::from_bounds and Interval::try_from_bounds

Interval::from_bounds builds the interval [x‾,x‾][\underline{x}, \overline{x}] from its endpoints, rounded outward to the requested precision.

pub fn Interval::from_bounds(@binary.Binary, @binary.Binary, precision? : Int) -> Self
pub fn Interval::try_from_bounds(@binary.Binary, @binary.Binary, precision? : Int) -> Result[Self, @arithmetic.ArithmeticError]

The default precision is the larger of the endpoint precisions. Infinite endpoints build unbounded intervals: from_bounds(-inf, +inf) is Entire. The inputs are invalid when an endpoint is NaN, the lower endpoint is +∞+\infty, the upper endpoint is −∞-\infty, or x‾>x‾\underline{x} > \overline{x}; from_bounds aborts and try_from_bounds returns a domain error. There is no way to build Empty from bounds; use Interval::empty.

///|
test "from_bounds" {
  let two = @binary.Binary::from_int(2, precision=53)
  let three = @binary.Binary::from_int(3, precision=53)
  inspect(fmt(@interval.Interval::from_bounds(two, three)), content="[2.00000e+0, 3.00000e+0]")
  inspect(@interval.Interval::try_from_bounds(three, two) is Err(_), content="true")
}

Interval::exact and Interval::try_exact

Interval::exact builds the singleton {x}\{x\} of a finite Binary.

pub fn Interval::exact(@binary.Binary, precision? : Int) -> Self
pub fn Interval::try_exact(@binary.Binary, precision? : Int) -> Result[Self, @arithmetic.ArithmeticError]

The default precision is that of x. When x has more significant bits than the requested precision, the singleton is rounded outward to the two-point interval [RD⁡p(x),RU⁡p(x)][\operatorname{RD}_p(x), \operatorname{RU}_p(x)]. A non-finite x aborts exact and makes try_exact return a domain error.

Interval::from_int and Interval::from_coefficient

Interval::from_int and Interval::from_coefficient build an enclosure of an integer.

pub fn Interval::from_int(Int, precision~ : Int) -> Self
pub fn Interval::from_coefficient(@binary.BinCoeff, precision? : Int, negative? : Bool) -> Self

The precision of from_int is required and counts bits (it was 53 by default). from_coefficient takes a non-negative BinCoeff magnitude and a separate sign. The integer is converted to a Binary exactly and then passed to exact, so the result is the singleton {n}\{n\} when nn fits in pp bits and the two-point interval [RD⁡p(n),RU⁡p(n)][\operatorname{RD}_p(n), \operatorname{RU}_p(n)] otherwise. Either way it contains nn. Pass a precision at least as large as the bit length of the integer to get a singleton.

Interval::from_double, Interval::try_from_double, Interval::from_float and Interval::try_from_float

These functions build the singleton of the exact binary value of a Double or Float.

pub fn Interval::from_double(Double, precision? : Int) -> Self
pub fn Interval::try_from_double(Double, precision? : Int) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::from_float(Float, precision? : Int) -> Self
pub fn Interval::try_from_float(Float, precision? : Int) -> Result[Self, @arithmetic.ArithmeticError]

Default precisions are 53 and 24. The conversion to Binary is exact; a smaller requested precision rounds the singleton outward. NaN and infinities abort the plain forms and are domain errors for the try_ forms. The result encloses the binary value, not the decimal literal it was written as: from_double(0.1) does not contain 1/101/10.

Interval::entire and Interval::empty

Interval::entire returns Entire and Interval::empty returns Empty.

pub fn Interval::entire(precision? : Int) -> Self
pub fn Interval::empty(precision? : Int) -> Self

The default precision is 53.

Observers

Interval::lower_bound and Interval::upper_bound

lower_bound and upper_bound are inf and sup of IEEE 1788-2015 12.12.8: they return the endpoints.

pub fn Interval::lower_bound(Self) -> @binary.Binary
pub fn Interval::upper_bound(Self) -> @binary.Binary

For an unbounded side the endpoint is an infinity. For Empty they return +∞+\infty and −∞-\infty respectively, so test is_empty first.

The sign of a zero follows 12.12.8: in a format with a signed zero a Level 1 value of 0 is returned as −0-0 by lower_bound and as +0+0 by every other function of the subclause (upper_bound, midpoint, radius, width, magnitude, mignitude and their contextual forms). So the lower bound of [0, 1] is −0-0 and the upper bound of [-1, 0] is +0+0, whatever sign of zero the interval was built from; [0, 0] has the representative (−0,+0)(-0, +0). An interval is a set: the sign of a stored zero is not part of it. Binary’s == agrees with compare (-0 == +0); identical tells the two zeros apart.

Every endpoint is a number of the format of pp bits (at most pp significant bits, on the grid of pp bits, the band below the range floor included) or an infinity, and its label, endpoint.precision(), is the precision pp of the interval. Binary’s == agrees with compare and ignores the label (Binary::identical compares it), so x.lower_bound() == y holds for a value y of the same number; Interval’s own == and identical compare the endpoints by value and never read a label. The sign of a stored zero is not part of the interval: the accessors decide it, as the paragraph above says.

Interval::midpoint and Interval::radius

midpoint is mid and radius is rad of IEEE 1788-2015 12.12.8 (the names mid, rad, wid, inf, sup, mag and mig are spelled out here; the standard’s short names would sit next to Binary::inf, so the long names are a documented exception).

pub fn Interval::midpoint(Self) -> @binary.Binary
pub fn Interval::radius(Self) -> @binary.Binary

Both are total; none aborts. midpoint returns NaN for Empty, 0 for Entire, the largest finite number of the format (the interval’s precision, the widest exponent range of Binary) with the sign of the unbounded side for a half-bounded interval, and otherwise the exact midpoint rounded to nearest (ties to even) at the interval’s precision. midpoint_ctx is the same observer for a given IntervalContext as the result format. radius returns NaN for Empty, +∞+\infty for every unbounded interval, and otherwise the smallest number rr of the precision with x⊆[m−r,m+r]\boldsymbol{x} \subseteq [m - r, m + r], where mm is the value midpoint returns: the larger of m−x‾m - \underline{x} and x‾−m\overline{x} - m, rounded up. This is measured from the rounded midpoint, not from the exact center, so [midpoint - radius, midpoint + radius] always contains the interval (before 0.12 the radius was the half-width and could miss a bound by up to half an ulp). For [1,1+3⋅2−52][1, 1 + 3 \cdot 2^{-52}] at 53 bits the midpoint is 1+2−511 + 2^{-51} and the radius 2−512^{-51}.

Interval::width

width returns RU⁡p(x‾−x‾)\operatorname{RU}_p(\overline{x} - \underline{x}), an upper bound of the exact width. It is NaN for Empty and +∞+\infty for unbounded intervals.

Interval::magnitude and Interval::mignitude

magnitude returns sup⁡{∣ξ∣:ξ∈x}\sup\{|\xi| : \xi \in \boldsymbol{x}\} and mignitude returns inf⁡{∣ξ∣:ξ∈x}\inf\{|\xi| : \xi \in \boldsymbol{x}\}.

pub fn Interval::magnitude(Self) -> @binary.Binary
pub fn Interval::mignitude(Self) -> @binary.Binary

For a non-empty interval,

mag⁡x=max⁡(∣x‾∣,∣x‾∣),mig⁡x={00∈x,min⁡(∣x‾∣,∣x‾∣)otherwise,\operatorname{mag}\boldsymbol{x} = \max(|\underline{x}|, |\overline{x}|), \qquad \operatorname{mig}\boldsymbol{x} = \begin{cases} 0 & 0 \in \boldsymbol{x}, \\ \min(|\underline{x}|, |\overline{x}|) & \text{otherwise,} \end{cases}

because ∣ξ∣|\xi| is convex, so its maximum over an interval is at an endpoint, and it is monotone on each side of 0. Both are exact. Empty gives NaN for both (12.12.8); magnitude of an unbounded interval is +∞+\infty.

///|
test "observers" {
  let x = iv(-3, 5)
  inspect(x.midpoint().to_string(), content="1p0")
  inspect(x.radius().to_string(), content="1p2")
  inspect(x.width().to_string(), content="1p3")
  inspect(x.magnitude().to_string(), content="5p0")
  inspect(x.mignitude().to_string(), content="0")
  inspect(iv(2, 7).mignitude().to_string(), content="1p1")
}

Interval::precision

precision returns the precision tag.

pub fn Interval::precision(Self) -> Int

Interval::is_empty, Interval::is_entire, Interval::is_common_interval, Interval::is_singleton

These predicates test the shape of the set.

pub fn Interval::is_empty(Self) -> Bool
pub fn Interval::is_entire(Self) -> Bool
pub fn Interval::is_common_interval(Self) -> Bool
pub fn Interval::is_singleton(Self) -> Bool

is_common_interval holds when the interval is non-empty with two finite endpoints (IEEE 1788-2015 10.6.3). is_singleton holds when x‾=x‾\underline{x} = \overline{x}. To ask whether an interval contains 0, use is_member with a zero.

Precision

Interval::with_precision

with_precision re-rounds an interval to a new precision without shrinking it.

pub fn Interval::with_precision(Self, Int) -> Self

The endpoints are rounded outward: the lower bound toward −∞-\infty and the upper bound toward +∞+\infty, because outward rounding is the only direction that keeps the result an enclosure; there is no rounding-mode argument. Empty stays Empty with the new precision.

///|
test "with_precision keeps the endpoints" {
  let one = @binary.Binary::one(precision=53)
  let next = @binary.Binary::make(
    @binary.BinCoeff::from_uint64((1UL << 52) + 1UL),
    -52,
    53,
  )
  let x = @interval.Interval::from_bounds(one, next)
  let y = x.with_precision(53)
  inspect(y.lower_bound().to_string(), content="1p0")
  inspect(y.upper_bound().to_string(), content="4503599627370497p-52")
  inspect(y.equal(x), content="true")
  // `normalized` keeps the endpoints too.
  inspect(x.normalized().equal(x), content="true")
}

Interval::normalized

normalized normalizes the two endpoints (Binary::normalized removes trailing zero bits) and stores them at the interval’s precision.

pub fn Interval::normalized(Self) -> Self

The stored endpoints are already representable at that precision, so the result is the same set as the input: normalized of [1,1+2−52][1, 1 + 2^{-52}] at 53 bits is [1,1+2−52][1, 1 + 2^{-52}]. Empty stays Empty.

Set operations

Interval::intersection and Interval::convex_hull

intersection returns x∩y\boldsymbol{x} \cap \boldsymbol{y} and convex_hull returns the smallest interval containing x∪y\boldsymbol{x} \cup \boldsymbol{y}.

pub fn Interval::intersection(Self, Self) -> Self
pub fn Interval::convex_hull(Self, Self) -> Self

For non-empty operands both are computed by endpoint max/min ([max⁡(x‾,y‾),min⁡(x‾,y‾)][\max(\underline{x}, \underline{y}), \min(\overline{x}, \overline{y})] and [min⁡(x‾,y‾),max⁡(x‾,y‾)][\min(\underline{x}, \underline{y}), \max(\overline{x}, \overline{y})]), exact apart from the final outward rounding to the larger precision. Disjoint intervals intersect to Empty, and an Empty operand makes the intersection Empty. When one operand of convex_hull is Empty, the result is the other operand at the larger of the two precisions, which is exact (see the note under Interval::with_precision).

Interval::cancel_plus and Interval::cancel_minus

cancel_minus(x, y) is the IEEE 1788 cancellative subtraction: in exact arithmetic it returns the interval z\boldsymbol{z} with y+z=x\boldsymbol{y} + \boldsymbol{z} = \boldsymbol{x}, which undoes a previous sum; cancel_plus(x, y) is cancel_minus(x, -y).

pub fn Interval::cancel_plus(Self, Self) -> Self
pub fn Interval::cancel_minus(Self, Self) -> Self

For bounded operands cancel_minus is [RD⁡(x‾−y‾),RU⁡(x‾−y‾)][\operatorname{RD}(\underline{x} - \underline{y}), \operatorname{RU}(\overline{x} - \overline{y})]. Indeed y+z=[y‾+z‾,y‾+z‾]\boldsymbol{y} + \boldsymbol{z} = [\underline{y} + \underline{z}, \overline{y} + \overline{z}], so y+z=x\boldsymbol{y} + \boldsymbol{z} = \boldsymbol{x} forces z‾=x‾−y‾\underline{z} = \underline{x} - \underline{y} and z‾=x‾−y‾\overline{z} = \overline{x} - \overline{y}, and this is an interval exactly when w(x)≥w(y)w(\boldsymbol{x}) \ge w(\boldsymbol{y}). Because of the outward rounding, the computed z\boldsymbol{z} satisfies y+z⊇x\boldsymbol{y} + \boldsymbol{z} \supseteq \boldsymbol{x}. When w(y)>w(x)w(\boldsymbol{y}) > w(\boldsymbol{x}), when an operand is unbounded, or when only y\boldsymbol{y} is empty, the result is Entire. Empty x\boldsymbol{x} with bounded or empty y\boldsymbol{y} gives Empty.

///|
test "set operations" {
  inspect(fmt(iv(0, 4).intersection(iv(2, 9))), content="[2.00000e+0, 4.00000e+0]")
  inspect(iv(0, 1).intersection(iv(2, 3)).is_empty(), content="true")
  inspect(fmt(iv(0, 1).convex_hull(iv(5, 6))), content="[-0.00000e+0, 6.00000e+0]")
  // (x + y) - y widens, cancel_minus recovers x.
  let x = iv(1, 2)
  let y = iv(10, 20)
  inspect(fmt(x + y - y), content="[-9.00000e+0, 1.20000e+1]")
  inspect(fmt((x + y).cancel_minus(y)), content="[1.00000e+0, 2.00000e+0]")
}

Relations

All relations are set relations of IEEE 1788; none of them is a total order. They never abort.

Interval::is_member

is_member tests whether a point belongs to the interval.

pub fn Interval::is_member(Self, @binary.Binary) -> Bool

It returns false for Empty and for a non-finite point (an unbounded interval contains all sufficiently large reals, but not ±∞\pm\infty or NaN). The trait method @lf_arith.Contains::contains instead takes two intervals and tests inclusion; see Enclosure relations.

Interval::subset, Interval::interior, Interval::equal, Interval::disjoint

These test inclusion, inclusion in the interior, equality and disjointness of sets.

pub fn Interval::subset(Self, Self) -> Bool
pub fn Interval::interior(Self, Self) -> Bool
pub fn Interval::equal(Self, Self) -> Bool
pub fn Interval::disjoint(Self, Self) -> Bool

x.subset(y) is x⊆y\boldsymbol{x} \subseteq \boldsymbol{y}, that is y‾≤x‾\underline{y} \le \underline{x} and x‾≤y‾\overline{x} \le \overline{y}. x.interior(y) is x⊆int⁡y\boldsymbol{x} \subseteq \operatorname{int} \boldsymbol{y}: each endpoint comparison is strict, except that two equal infinite endpoints count as interior (the interior of [a,+∞)[a, +\infty) is (a,+∞)(a, +\infty), so Entire is interior to itself). Empty is a subset of, interior to and disjoint from every interval. equal is the method of the Eq implementation, so x == y is x.equal(y): the two intervals are the same set (two empty intervals are equal), whatever their precision tags and the representation of their endpoints (IEEE 1788-2015 12.3 and 12.12.9).

Interval::identical

identical compares the datum, not only the set (12.3): the same set and the same precision tag.

pub fn Interval::identical(Self, Self) -> Bool

The same interval at 24 and at 113 bits is == and not identical; use identical where the precision matters, for example to check that a result has the precision that was asked for. Two empty intervals are identical when their precisions are equal.

The same holds for any other part of the format of an interval that a later release adds (the optional exponent range of the 754-conforming types, issue 232): the format is not part of == or of compare; only identical may look at it.

Interval::less, Interval::strict_less, Interval::precedes, Interval::strict_precedes

These are the order relations of IEEE 1788.

pub fn Interval::less(Self, Self) -> Bool
pub fn Interval::strict_less(Self, Self) -> Bool
pub fn Interval::precedes(Self, Self) -> Bool
pub fn Interval::strict_precedes(Self, Self) -> Bool

For non-empty operands:

RelationSet definitionCondition
less∀ξ ∃η:ξ≤η\forall\xi\,\exists\eta: \xi \le \eta and ∀η ∃ξ:ξ≤η\forall\eta\,\exists\xi: \xi \le \etax‾≤y‾\underline{x} \le \underline{y} and x‾≤y‾\overline{x} \le \overline{y}
strict_lessthe same with <<x‾<y‾\underline{x} < \underline{y} (or both −∞-\infty) and x‾<y‾\overline{x} < \overline{y} (or both +∞+\infty)
precedes∀ξ ∀η:ξ≤η\forall\xi\,\forall\eta: \xi \le \etax‾≤y‾\overline{x} \le \underline{y}
strict_precedes∀ξ ∀η:ξ<η\forall\xi\,\forall\eta: \xi < \etax‾<y‾\overline{x} < \underline{y}

With Empty: less and strict_less hold only when both are Empty; precedes and strict_precedes hold when either is Empty.

Interval::overlap

overlap classifies the relative position of two intervals.

pub fn Interval::overlap(Self, Self) -> OverlapState

The result is one of the sixteen states of OverlapState; it is computed from the comparisons of the four endpoints, testing equal endpoints first, so a singleton that coincides with an endpoint of the other interval gives Starts, Finishes, StartedBy or FinishedBy rather than Meets or MetBy, as IEEE 1788 requires.

///|
test "relations" {
  let a = iv(1, 3)
  let b = iv(3, 6)
  inspect(a.precedes(b), content="true")
  inspect(a.strict_precedes(b), content="false")
  inspect(@lf_arith.DefinitelyLe::definitely_le(a, b), content="true")
  inspect(@lf_arith.MaybeEq::maybe_eq(a, b), content="true")
  inspect(iv(2, 3).interior(iv(1, 6)), content="true")
  inspect(iv(1, 3).interior(iv(1, 6)), content="false")
  debug_inspect(a.overlap(b), content="Meets")
  debug_inspect(iv(1, 6).overlap(iv(2, 3)), content="Contains")
}

Arithmetic

Interval::add, Interval::sub, Interval::mul, Interval::div

The four basic operations return the outward-rounded hull of {ξ∘η:ξ∈x,η∈y}\{\xi \circ \eta : \xi \in \boldsymbol{x}, \eta \in \boldsymbol{y}\}; they are also available as the operators +, -, *, /.

pub fn Interval::add(Self, Self) -> Self
pub fn Interval::sub(Self, Self) -> Self
pub fn Interval::mul(Self, Self) -> Self
pub fn Interval::div(Self, Self) -> Self

The result precision is the larger operand precision; an Empty operand gives Empty. Endpoint formulas:

x+y=[RD⁡(x‾+y‾), RU⁡(x‾+y‾)]x−y=[RD⁡(x‾−y‾), RU⁡(x‾−y‾)]x⋅y=[RD⁡min⁡S, RU⁡max⁡S],S={x‾y‾,x‾y‾,x‾y‾,x‾y‾}\begin{aligned} \boldsymbol{x} + \boldsymbol{y} &= [\operatorname{RD}(\underline{x} + \underline{y}),\ \operatorname{RU}(\overline{x} + \overline{y})] \\ \boldsymbol{x} - \boldsymbol{y} &= [\operatorname{RD}(\underline{x} - \overline{y}),\ \operatorname{RU}(\overline{x} - \underline{y})] \\ \boldsymbol{x} \cdot \boldsymbol{y} &= [\operatorname{RD}\min S,\ \operatorname{RU}\max S],\quad S = \{\underline{x}\underline{y}, \underline{x}\overline{y}, \overline{x}\underline{y}, \overline{x}\overline{y}\} \end{aligned}

with 0⋅∞0 \cdot \infty taken as 0 in SS (a zero endpoint times an unbounded side contributes 0). The sums and products are formed exactly and rounded once. For bounded operands the signs select the products that can be extremal: two when both operands have constant sign, four (the minimum of x‾ y‾\underline{x}\,\overline{y} and x‾ y‾\overline{x}\,\underline{y}, the maximum of x‾ y‾\underline{x}\,\underline{y} and x‾ y‾\overline{x}\,\overline{y}) when either operand has 0 in its interior. The design page proves the sign-case table.

Division follows IEEE 1788: x/y\boldsymbol{x} / \boldsymbol{y} is the hull of {ξ/η:ξ∈x,η∈y,η≠0}\{\xi/\eta : \xi \in \boldsymbol{x}, \eta \in \boldsymbol{y}, \eta \ne 0\}.

Divisor y\boldsymbol{y}Result
0∉y0 \notin \boldsymbol{y}[RD⁡min⁡Q,RU⁡max⁡Q][\operatorname{RD}\min Q, \operatorname{RU}\max Q] over the endpoint quotients QQ
{0}\{0\}Empty
y‾<0<y‾\underline{y} < 0 < \overline{y}Entire, unless x={0}\boldsymbol{x} = \{0\}
[0,y‾][0, \overline{y}] or [y‾,0][\underline{y}, 0]half-unbounded (see below), or Entire when x‾<0<x‾\underline{x} < 0 < \overline{x}

When the divisor touches 0 at one end, the quotient is unbounded on one side: for example [1,2]/[0,4]=[1/4,+∞)[1, 2]/[0, 4] = [1/4, +\infty) and [−2,−1]/[0,4]=(−∞,−1/4][-2, -1]/[0, 4] = (-\infty, -1/4]. A dividend equal to {0}\{0\} gives {0}\{0\} for any divisor other than {0}\{0\}. Each selected quotient is computed by one directed division at the result precision.

///|
test "basic arithmetic" {
  let x = iv(1, 2)
  let y = iv(-3, 5)
  inspect(fmt(x + y), content="[-2.00000e+0, 7.00000e+0]")
  inspect(fmt(x - y), content="[-4.00000e+0, 5.00000e+0]")
  inspect(fmt(x * y), content="[-6.00000e+0, 1.00000e+1]")
  inspect((x / y).is_entire(), content="true")
  inspect(fmt(x / iv(0, 4)), content="[2.50000e-1, inf]")
  inspect((x / iv(0, 0)).is_empty(), content="true")
}

Interval::neg and Interval::abs

neg returns [−x‾,−x‾][-\overline{x}, -\underline{x}] and abs returns {∣ξ∣:ξ∈x}\{|\xi| : \xi \in \boldsymbol{x}\}.

pub fn Interval::neg(Self) -> Self
pub fn Interval::abs(Self) -> Self

abs is x\boldsymbol{x} when x‾≥0\underline{x} \ge 0, −x-\boldsymbol{x} when x‾≤0\overline{x} \le 0, and [0,mag⁡x][0, \operatorname{mag}\boldsymbol{x}] otherwise. Both are exact. neg is also the unary operator -.

Interval::recip

recip returns 1/x1/\boldsymbol{x} with the division rules above.

pub fn Interval::recip(Self) -> Self

Interval::sqr and Interval::pown

sqr returns {ξ2}\{\xi^2\} and pown returns {ξn}\{\xi^n\} for an integer exponent nn.

pub fn Interval::sqr(Self) -> Self
pub fn Interval::pown(Self, Int) -> Self

Unlike x * x, these use the same point twice, so [-1, 2].sqr() is [0,4][0, 4] (while x * x is [−2,4][-2, 4]): sqr is [mig⁡(x)2,mag⁡(x)2][\operatorname{mig}(\boldsymbol{x})^2, \operatorname{mag}(\boldsymbol{x})^2]. pown evaluates the monotone pieces of ξn\xi^n at the endpoints with directed rounding: odd positive powers are increasing; even positive powers decrease then increase, with minimum 0 when 0∈x0 \in \boldsymbol{x}; negative powers have a pole at 0. pown(x, 0) is {1}\{1\} for every non-empty x; Empty stays Empty. pown(x, n) with n<0n < 0 returns Empty for x={0}\boldsymbol{x} = \{0\}, a half-unbounded interval when 0 is an endpoint, and for 0 in the interior Entire (odd nn) or [min⁡(x‾n,x‾n),+∞)[\min(\underline{x}^n, \overline{x}^n), +\infty) (even nn). As a shortcut, n<−4096n < -4096 with 0 in the interior returns Entire even for even nn; this is a valid but not tight enclosure.

///|
test "powers" {
  let x = iv(-1, 2)
  inspect(fmt(x.sqr()), content="[-0.00000e+0, 4.00000e+0]")
  inspect(fmt(x.pown(3)), content="[-1.00000e+0, 8.00000e+0]")
  inspect(fmt(x.pown(-2)), content="[2.50000e-1, inf]")
  inspect(x.pown(-1).is_entire(), content="true")
  inspect(fmt(iv(0, 2).pown(-1)), content="[5.00000e-1, inf]")
}

Interval::fma

fma(x, y, z) returns an enclosure of {ξη+ζ}\{\xi\eta + \zeta\} with a single outward rounding.

pub fn Interval::fma(Self, Self, Self) -> Self

The exact product bounds are computed as for mul and added to the endpoints of z\boldsymbol{z} before the final rounding, so the result is never wider than x * y + z.

Interval::min and Interval::max

min and max return {min⁡(ξ,η)}\{\min(\xi, \eta)\} and {max⁡(ξ,η)}\{\max(\xi, \eta)\}.

pub fn Interval::min(Self, Self) -> Self
pub fn Interval::max(Self, Self) -> Self

min is [min⁡(x‾,y‾),min⁡(x‾,y‾)][\min(\underline{x}, \underline{y}), \min(\overline{x}, \overline{y})] and max is the analogue with max: min⁡\min is increasing in each argument. An Empty operand gives Empty.

Interval::sign, Interval::ceil, Interval::floor, Interval::trunc, Interval::round_ties_to_even, Interval::round_ties_to_away

The integer functions of IEEE 1788-2015 Table 9.1. sign is −1-1, 00 or 11 by the sign of the point; ceil and floor give the smallest integer not less and the largest integer not greater than the point; trunc the nearest integer toward zero; round_ties_to_even and round_ties_to_away the nearest integer, a tie going to the even integer or away from zero (the names are the 754 roundTiesToEven and roundTiesToAway).

pub fn Interval::sign(Self) -> Self
pub fn Interval::ceil(Self) -> Self
pub fn Interval::floor(Self) -> Self
pub fn Interval::trunc(Self) -> Self
pub fn Interval::round_ties_to_even(Self) -> Self
pub fn Interval::round_ties_to_away(Self) -> Self

Each function ff is nondecreasing, so the result is [f(x‾),f(x‾)][f(\underline{x}), f(\overline{x})]. The values are integers (or −1-1, 00, 11), so the result is exact: nothing is rounded, the precision tag is kept, and a zero bound is stored as +0+0. The function of ±∞\pm\infty is ±∞\pm\infty (for sign, ±1\pm 1). An Empty operand gives Empty. There is no try_ form: no input fails.

///|
test "integer functions" {
  let x = @interval.Interval::from_bounds(
    @binary.Binary::from_double(1.1),
    @binary.Binary::from_double(2.0),
  )
  assert_true(x.ceil() == iv(2, 2))
  assert_true(x.floor() == iv(1, 2))
  let d = @interval.DecoratedInterval::new(x)
  assert_eq(d.ceil().decoration(), @interval.Decoration::Dac)
  assert_eq(d.floor().decoration(), @interval.Decoration::Def)
}

Interval::sqr_rev, Interval::abs_rev, Interval::pown_rev and Interval::cosh_rev

IEEE 1788-2015 10.5.4 and Table 10.1. Each is the natural reverse extension: the hull of { x∈x∣φ(x)∈c }\{\, x \in \boldsymbol{x} \mid \varphi(x) \in \boldsymbol{c} \,\}, where c\boldsymbol{c} is the receiver and the prior x\boldsymbol{x} is the optional last argument (default Entire). The hull is taken after meeting the preimage with x\boldsymbol{x}, not before: for c=[1,4]\boldsymbol{c} = [1, 4], sqr_rev is [−2,2][-2, 2] and with the prior [0,1.2][0, 1.2] it is [1,1.2][1, 1.2], while [−2,2]∩[0,1.2]=[0,1.2][-2, 2] \cap [0, 1.2] = [0, 1.2].

pub fn Interval::sqr_rev(Self, x? : Self) -> Self
pub fn Interval::abs_rev(Self, x? : Self) -> Self
pub fn Interval::pown_rev(Self, Int, x? : Self) -> Self
pub fn Interval::cosh_rev(Self, x? : Self) -> Self

pown_rev(c, p, x?) is the standard’s pownRev(c, x, p): the power comes before the optional prior. The functions:

FunctionPreimage of c\boldsymbol{c}
sqr_rev±c∩[0,+∞)\pm\sqrt{\boldsymbol{c} \cap [0, +\infty)}, the endpoints of the roots rounded outward
abs_rev±(c∩[0,+∞))\pm(\boldsymbol{c} \cap [0, +\infty)), exact
cosh_rev±acosh⁡(c∩[1,+∞))\pm\operatorname{acosh}(\boldsymbol{c} \cap [1, +\infty))
pown_rev, p=0p = 0R\mathbb{R} if 1∈c1 \in \boldsymbol{c}, else empty (x0=1x^0 = 1 for every xx)
pown_rev, pp even and positive±c∩[0,+∞)p\pm\sqrt[p]{\boldsymbol{c} \cap [0, +\infty)}
pown_rev, pp odd and positivecp\sqrt[p]{\boldsymbol{c}}, one interval (p=1p = 1: c\boldsymbol{c})
pown_rev, pp even and negativex≠0x \ne 0 with xp∈c∩(0,+∞)x^p \in \boldsymbol{c} \cap (0, +\infty): ±\pm the ∣p∣\lvert p\rvert-th root of 1/c1/\boldsymbol{c}, the upper end of c\boldsymbol{c} bounding ∣x∣\lvert x\rvert from below and the lower end from above
pown_rev, pp odd and negativethe positive part of c\boldsymbol{c} gives positive xx and the negative part gives negative xx, each by ⋅p\sqrt[p]{\cdot} with the pole 0 excluded

An Empty c\boldsymbol{c}, or a c\boldsymbol{c} outside the range of the function (negative for sqr_rev, below 1 for cosh_rev), gives Empty. The root endpoints are directed roundings of exact points, so the results are the tightest in the type. For a negative power the value x=0x = 0 is not in the domain, so the component that ends at 0 (when c\boldsymbol{c} is unbounded above for an even pp, or reaches the pole) is open there: with c=[1,+∞)\boldsymbol{c} = [1, +\infty) and p=−2p = -2 the set is [−1,0)∪(0,1][-1, 0) \cup (0, 1] and the prior [0,0][0, 0] gives Empty. The result precision is the largest of the operands’.

///|
test "sqr_rev and pown_rev" {
  let c = iv(1, 4)
  inspect(c.sqr_rev().lower_bound().to_string() + " " + c.sqr_rev().upper_bound().to_string(), content="-1p1 1p1")
  assert_true(c.sqr_rev(x=iv(0, 1)) == iv(1, 1))
  assert_true(iv(16, 81).pown_rev(4, x=iv(0, 5)) == iv(2, 3))
  assert_true(iv(1, 4).pown_rev(0) == @interval.Interval::entire())
}

Interval::sin_rev, Interval::cos_rev and Interval::tan_rev

IEEE 1788-2015 10.5.4 and Table 10.1. Each is the hull of { x∈x∣φ(x)∈c }\{\, x \in \boldsymbol{x} \mid \varphi(x) \in \boldsymbol{c} \,\} for the receiver c\boldsymbol{c} and the optional prior x\boldsymbol{x} (default Entire).

pub fn Interval::sin_rev(Self, x? : Self) -> Self
pub fn Interval::cos_rev(Self, x? : Self) -> Self
pub fn Interval::tan_rev(Self, x? : Self) -> Self

The preimage is a periodic union of intervals. With c′=c∩[−1,1]\boldsymbol{c}' = \boldsymbol{c} \cap [-1, 1], A=arcsin⁡c′‾A = \arcsin \underline{c'} and B=arcsin⁡c′‾B = \arcsin \overline{c'}, the preimage of sin_rev is ⋃k[A+2πk,B+2πk]∪[π−B+2πk,π−A+2πk]\bigcup_k [A + 2\pi k, B + 2\pi k] \cup [\pi - B + 2\pi k, \pi - A + 2\pi k]; cos_rev and tan_rev are analogous (tan_rev: ⋃k(arctan⁡c‾+πk,arctan⁡c‾+πk)\bigcup_k (\arctan \underline{c} + \pi k, \arctan \overline{c} + \pi k), a bound at ±∞\pm\infty giving the pole ±π/2+πk\pm\pi/2 + \pi k, which is not in the domain). With the default prior the result is Entire for every c\boldsymbol{c} that meets the range of the function; c\boldsymbol{c} outside [−1,1][-1, 1] gives Empty for sin_rev and cos_rev, and c⊇[−1,1]\boldsymbol{c} \supseteq [-1, 1] (tan_rev: c=\boldsymbol{c} = Entire) returns the prior itself. With a bounded prior only the first and the last piece that meet it matter, so the cost does not depend on how many periods the prior spans.

The result is the hull of the true set in the type: every comparison of a prior end with a piece end is decided exactly, and an end of the result that comes from a piece is the exact directed rounding of that end (RD for a lower end, RU for an upper end). This is the tightest result, and it can be narrower than a reference value that leaves an ulp of slack. For example sin_rev([0, 0], x = [RU(pi), 7]) is [RD(2π),RU(2π)][RD(2\pi), RU(2\pi)] and sin_rev([0, 0], x = [RU(pi), 6]) is Empty. How the ends are decided is on the design page. The one limit is the forward trigonometric one: an end of the prior at or beyond 2max⁡(65536,4p)+12^{\max(65536, 4p) + 1} in magnitude is kept as it is (valid, not tight), decided before any work is done, and a prior whose finite ends are all beyond it is returned at once. For a prior end of magnitude 2e2^e inside the limit the cost grows with ee like the cost of the forward functions of the trigonometric functions section, the working precision following ee.

///|
test "sin_rev with a prior" {
  let rd_pi = @binary.Binary::from_double(3.141592653589793)
  let ru_pi = @binary.Binary::from_double(3.1415926535897936)
  let c = iv(0, 0)
  // the multiples of pi in [3, 4]: only pi, which is not a float
  let r = c.sin_rev(x=iv(3, 4))
  assert_true(r.lower_bound().compare(rd_pi) == 0)
  assert_true(r.upper_bound().compare(ru_pi) == 0)
  // the prior starts above pi and ends before 2 pi: nothing
  let six = @binary.Binary::from_int(6)
  let beyond = @interval.Interval::from_bounds(ru_pi, six)
  assert_true(c.sin_rev(x=beyond).is_empty())
  // the default prior
  assert_true(c.sin_rev().is_entire())
}

Interval::pow_rev1

IEEE 1788-2015 Table 10.1. b.pow_rev1(c, x?) is the hull of { x∈x∣∃ β∈b:xβ is defined and in c }\{\, x \in \boldsymbol{x} \mid \exists\, \beta \in \boldsymbol{b} : x^\beta \text{ is defined and in } \boldsymbol{c} \,\} for the optional prior x\boldsymbol{x} (default Entire); the receiver is the exponent interval b\boldsymbol{b}. xβx^\beta is defined for x>0x > 0 and for x=0x = 0 with β>0\beta > 0 (value 0).

pub fn Interval::pow_rev1(Self, Self, x? : Self) -> Self

For x>0x > 0, xβ∈cx^\beta \in \boldsymbol{c} means βln⁡x∈ln⁡(c∩(0,+∞))\beta \ln x \in \ln(\boldsymbol{c} \cap (0, +\infty)), so the set is exp⁡(L/setb)\exp(L /_{\text{set}} \boldsymbol{b}) with L=ln⁡(c∩(0,+∞))L = \ln(\boldsymbol{c} \cap (0, +\infty)), the set division of mul_rev in logarithm coordinates, plus the point 0 when 0∈c0 \in \boldsymbol{c} and b\boldsymbol{b} has a positive point. Every end of a piece is cend1/βendc_\text{end}^{1/\beta_\text{end}}, 0, 1 or infinite. The ends that are not attained are open: 0 (from ln⁡x→−∞\ln x \to -\infty, unless the zero part closes it) and 1 (the limit of a quotient by an unbounded b\boldsymbol{b}); a prior that only touches such an end does not meet the set. For example pow_rev1([1, +inf), [2, +inf)) is (1,+∞)(1, +\infty), so with the prior [0,1][0, 1] the result is Empty, and pow_rev1([-1, 1], [0.5, 2]) is (0,+∞)(0, +\infty), so with the prior [0,0][0, 0] it is Empty.

The result is the hull in the type: every comparison of a prior end with a piece end is exact and an end written to the result is the exact directed rounding of the piece end. The exact value of c1/βc^{1/\beta} is classified from the structure of cc and β\beta (no squaring): it is a float candidate (dyadic), a rational that is not a float (for example 91/(−2)=1/39^{1/(-2)} = 1/3), or irrational, and the last is decided by a loop that raises the working precision as sin_rev does. The design page has the classes, the budgets and their cost. An end of the set above the largest finite float is written as +∞+\infty when it is an upper end and as the largest finite float of the result precision when it is a lower end; an end below the smallest positive stored value is written as 0 when it is a lower end and as the smallest positive stored value when it is an upper end; in between, including the subnormal range, the end is the usual directed rounding. An exponent of magnitude 21092^{10^9} is decided at once because the sign of ln⁡(c)/β\ln(c)/\beta is exact.

///|
test "pow_rev1" {
  // x^2 in [4, 4] with x > 0: x = 2
  assert_true(iv(2, 2).pow_rev1(iv(4, 4)) == iv(2, 2))
  // x^beta in [1, 1] for beta in [-4, -2] with the prior x = [1, 1]: x = 1
  let r = iv(-4, -2).pow_rev1(iv(1, 1), x=iv(1, 1))
  assert_true(r == iv(1, 1))
  // 0^beta = 0 for beta > 0
  assert_true(iv(1, 2).pow_rev1(iv(0, 0)) == iv(0, 0))
}

Interval::pow_rev2

IEEE 1788-2015 Table 10.1. a.pow_rev2(c, x?) is the hull of { β∈x∣∃ a0∈a:a0β is defined and in c }\{\, \beta \in \boldsymbol{x} \mid \exists\, a_0 \in \boldsymbol{a} : a_0^\beta \text{ is defined and in } \boldsymbol{c} \,\} for the optional prior x\boldsymbol{x} (default Entire); the receiver is the base interval a\boldsymbol{a} and the unknown is the exponent. a0βa_0^\beta is defined for a0>0a_0 > 0 and for a0=0a_0 = 0 with β>0\beta > 0 (value 0).

pub fn Interval::pow_rev2(Self, Self, x? : Self) -> Self

For a0>0a_0 > 0, a0β∈ca_0^\beta \in \boldsymbol{c} means βln⁡a0∈ln⁡(c∩(0,+∞))\beta \ln a_0 \in \ln(\boldsymbol{c} \cap (0, +\infty)), so the set is L/setML /_{\text{set}} M with L=ln⁡(c∩(0,+∞))L = \ln(\boldsymbol{c} \cap (0, +\infty)) and M=ln⁡(a∩(0,+∞))M = \ln(\boldsymbol{a} \cap (0, +\infty)), the set division of mul_rev in logarithm coordinates, plus (0,+∞)(0, +\infty) when 0∈a0 \in \boldsymbol{a} and 0∈c0 \in \boldsymbol{c} (the base 0). The base 1 is the branch ”00 in the divisor”: if 1∈a1 \in \boldsymbol{a} and 1∈c1 \in \boldsymbol{c} every exponent qualifies, and if a=[1,1]\boldsymbol{a} = [1, 1] and 1∉c1 \notin \boldsymbol{c} there is none. Every end of a piece is ln⁡(cend)/ln⁡(aend)\ln(c_\text{end}) / \ln(a_\text{end}), 0 or infinite. The ends that are not attained are open: the infinities, and 0 when it is the limit of a quotient by an unbounded MM (and 0∉L0 \notin L); a prior that only touches such an end does not meet the set. For example pow_rev2([2, +inf), [2, 4]) is (0,2](0, 2], so with the prior [−3,0][-3, 0] the result is Empty, while with c=[1,4]\boldsymbol{c} = [1, 4] the end 0 is attained and the result is [0,0][0, 0].

The result is the hull in the type: every comparison of a prior end with a piece end is exact and an end written to the result is the exact directed rounding of the piece end. The value r=ln⁡(C)/ln⁡(A)r = \ln(C)/\ln(A) of an end is classified from the structure of AA and CC: it is rational iff AA and CC are multiplicatively dependent, decided by the multiplicative Euclidean algorithm on the odd parts (an inexact division proves independence). A rational is a float iff its reduced denominator is a power of two, and otherwise it is a rational that is not a float (for example ln⁡3/ln⁡27=1/3\ln 3 / \ln 27 = 1/3); every other end is irrational and is decided by a loop that raises the working precision as sin_rev does. The design page has the classes, the budgets and their cost. A base one unit from 1 gives a huge quotient, and the first working precision follows its magnitude.

///|
test "pow_rev2" {
  // 2^beta in [8, 8] gives beta = 3
  assert_true(iv(2, 2).pow_rev2(iv(8, 8)) == iv(3, 3))
  // 2^beta in [1, 1] gives beta = 0
  assert_true(iv(2, 2).pow_rev2(iv(1, 1)) == iv(0, 0))
  // a prior restricts the result: 2^beta = 4 has the only solution beta = 2
  assert_true(iv(2, 2).pow_rev2(iv(4, 4), x=iv(0, 5)) == iv(2, 2))
}

Interval::atan2_rev1 and Interval::atan2_rev2

IEEE 1788-2015 Table 10.1, equations (6) and (7) of 10.5.4. b.atan2_rev1(c, x?) is the hull of { y∈x∣∃ b0∈b:atan2⁡(y,b0) is defined and in c }\{\, y \in \boldsymbol{x} \mid \exists\, b_0 \in \boldsymbol{b} : \operatorname{atan2}(y, b_0) \text{ is defined and in } \boldsymbol{c} \,\}: the receiver is the abscissa interval b\boldsymbol{b} and the unknown is the ordinate yy. a.atan2_rev2(c, x?) is the hull of { x0∈x∣∃ a0∈a:atan2⁡(a0,x0) is defined and in c }\{\, x_0 \in \boldsymbol{x} \mid \exists\, a_0 \in \boldsymbol{a} : \operatorname{atan2}(a_0, x_0) \text{ is defined and in } \boldsymbol{c} \,\}: the receiver is the ordinate interval a\boldsymbol{a} and the unknown is the abscissa x0x_0. The optional prior x\boldsymbol{x} defaults to Entire.

pub fn Interval::atan2_rev1(Self, Self, x? : Self) -> Self
pub fn Interval::atan2_rev2(Self, Self, x? : Self) -> Self

atan2⁡(y,x)\operatorname{atan2}(y, x) is defined on the plane minus the origin, with the range (−π,π](-\pi, \pi] (Table 9.1, footnote f): the angle π\pi is attained on the half-line y=0y = 0, x<0x < 0, and −π-\pi is never attained. With Θ=c∩(−π,π]\Theta = \boldsymbol{c} \cap (-\pi, \pi] the set is the projection of the sector { r(cos⁡t,sin⁡t):r>0, t∈Θ }\{\, r(\cos t, \sin t) : r > 0,\ t \in \Theta \,\} on the axis of the unknown, cut by the strip of the given operand. The design page has the case table by angle region and by the sign of the operand, the open ends, the branch cut and the origin. The set is empty when c\boldsymbol{c} has no point in (−π,π](-\pi, \pi] (for example [4,5][4, 5]), when an operand or the prior is Empty, and for the abscissa {0}\{0\} (Rev1) or the ordinate {0}\{0\} (Rev2) when c\boldsymbol{c} misses the angles ±π/2\pm\pi/2 (Rev1) or 00 and π\pi (Rev2); the origin is never part of the set.

The result is the hull in the type: every comparison of a prior end with a piece end is exact, and an end written to the result is the exact directed rounding of the piece end. The exact ends are 0 and the infinities; every other end is bendtan⁡(cend)b_\text{end} \tan(c_\text{end}) (Rev1) or aend/tan⁡(cend)a_\text{end} / \tan(c_\text{end}) (Rev2) of nonzero floats, which is irrational (the tangent of a nonzero algebraic number is transcendental), so it differs from every float and a loop that raises the working precision decides it, as in sin_rev. Whether an end of c\boldsymbol{c} is below or above a multiple of π/2\pi/2 is decided exactly (π\pi is irrational, so a float is never equal to such a multiple).

///|
test "atan2_rev1 and atan2_rev2" {
  // the angle 0 with a positive abscissa: the ordinate is 0
  assert_true(iv(1, 1).atan2_rev1(iv(0, 0)) == iv(0, 0))
  // c = [4, 5] has no point in (-pi, pi]: Empty; so has the origin
  assert_true(iv(1, 1).atan2_rev1(iv(4, 5)).is_empty())
  assert_true(iv(0, 0).atan2_rev1(iv(0, 0)).is_empty())
  // the angle 0 with the ordinate {0} and a prior x0 in [1, 2]: the abscissa interval of the prior
  assert_true(iv(0, 0).atan2_rev2(iv(0, 0), x=iv(1, 2)) == iv(1, 2))
}

Interval::mul_rev_to_pair and Interval::mul_rev

IEEE 1788-2015 10.5.5 and Table 10.1. For intervals b\boldsymbol{b} and c\boldsymbol{c} the set

c/setb={ x∈R∣∃ y∈b:xy∈c }\boldsymbol{c} \mathbin{/_{\text{set}}} \boldsymbol{b} = \{\, x \in \mathbb{R} \mid \exists\, y \in \boldsymbol{b} : x y \in \boldsymbol{c} \,\}

has zero, one or two connected components, and is not always closed ([1,1]/set[1,+∞)=(0,1][1, 1] /_{\text{set}} [1, +\infty) = (0, 1]). mul_rev_to_pair returns the closures of the components, ordered, as a pair; mul_rev returns the hull of the part of the set that lies in the prior interval x.

pub fn Interval::mul_rev_to_pair(Self, Self) -> (Self, Self)
pub fn Interval::mul_rev(Self, Self, x? : Self) -> Self

mul_rev_to_pair(b, c) is (Empty, Empty) when there is no component, (u, Empty) for one, and (u, v) with u<vu < v for two. The two closures can share an endpoint: [1,1]/setEntire=(−∞,0)∪(0,+∞)[1, 1] /_{\text{set}} \text{Entire} = (-\infty, 0) \cup (0, +\infty) gives ([-inf, 0], [0, +inf]). An Empty operand gives (Empty, Empty). The receiver is b\boldsymbol{b} and the argument is c\boldsymbol{c}, as in the standard’s mulRevToPair(b, c).

mul_rev(b, c, x?) is hull⁡{x∈x∣∃y∈b:xy∈c}\operatorname{hull}\{x \in \boldsymbol{x} \mid \exists y \in \boldsymbol{b} : x y \in \boldsymbol{c}\} with the default x=\boldsymbol{x} = Entire. The hull is of the set and not of its closure, and not the intersection of x with the hull of the set: with b=[−1,1]\boldsymbol{b} = [-1, 1], c=[1,1]\boldsymbol{c} = [1, 1] and x=[0,0.5]\boldsymbol{x} = [0, 0.5] the result is Empty, whereas the hull of the set is Entire. An endpoint 0 that is the unattained limit of a quotient by an unbounded b\boldsymbol{b} counts as open, so mul_rev([1, +inf), [1, 1], x=[-1, 0]) is Empty (the set is (0,1](0, 1]) and with x=[0,0.5]\boldsymbol{x} = [0, 0.5] it is [0,0.5][0, 0.5]. The endpoints of the components are quotients rounded outward, so the results are the tightest in the type. The result precision is the largest of the operands’.

///|
test "mul_rev_to_pair and mul_rev" {
  let b = @interval.Interval::from_bounds(
    @binary.Binary::from_int(-1),
    @binary.Binary::from_int(1),
  )
  let (u, v) = b.mul_rev_to_pair(iv(1, 1))
  // (-inf, -1] and [1, +inf)
  inspect(u.upper_bound().to_string() + " " + v.lower_bound().to_string(), content="-1p0 1p0")
  assert_true(b.mul_rev(iv(1, 1), x=iv(0, 0)).is_empty())
}

Elementary functions

Each function ff returns an interval containing f(x∩Df)f(\boldsymbol{x} \cap D_f), where DfD_f is the domain of ff; points of x\boldsymbol{x} outside DfD_f are ignored and the result is Empty when x∩Df\boldsymbol{x} \cap D_f is empty. The result precision is the argument’s precision.

Functions come in two forms, and there is one kernel. The try_ form (try_exp, …) evaluates each endpoint with the corresponding binary try_*_ctx function rounded toward −∞-\infty or +∞+\infty, and returns Err(ArithmeticError) with a certification-failure detail naming the operation, stage and reason when that evaluation runs out of its work budget. The total form (exp, sin, …) is the try_ form with a fallback: it returns the same interval whenever the try_ form succeeds, and otherwise the range of the function over its domain (the fallbacks are listed below), which is a valid but wide enclosure. A total form never aborts, at any precision the type accepts; a domain error is not a failure (the result is Empty), so an argument outside the domain and a certification failure give different results. Nothing is computed twice: the total form calls the try_ form once.

Interval::sqrt

sqrt returns x∩[0,+∞)\sqrt{\boldsymbol{x} \cap [0, +\infty)}.

pub fn Interval::sqrt(Self) -> Self

The endpoints are the downward and upward square roots at the interval’s precision. Empty when x‾<0\overline{x} < 0. There is no try_ form: square root never fails.

Interval::exp, Interval::exp2, Interval::exp10, Interval::expm1, Interval::try_exp, Interval::try_exp2, Interval::try_exp10, Interval::try_expm1

These return enclosures of eξe^{\xi}, 2ξ2^{\xi}, 10ξ10^{\xi} and eξ−1e^{\xi} - 1.

pub fn Interval::exp(Self) -> Self
pub fn Interval::exp2(Self) -> Self
pub fn Interval::exp10(Self) -> Self
pub fn Interval::expm1(Self) -> Self
pub fn Interval::try_exp(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_exp2(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_exp10(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_expm1(Self) -> Result[Self, @arithmetic.ArithmeticError]

All four are increasing, so the result is [RD⁡f(x‾),RU⁡f(x‾)][\operatorname{RD} f(\underline{x}), \operatorname{RU} f(\overline{x})]. For ξ≥230\xi \ge 2^{30} the enclosure of all four is [largest finite,+∞)[\text{largest finite}, +\infty); for ξ≤−230\xi \le -2^{30} that of exp, exp2 and exp10 is [0,smallest positive][0, \text{smallest positive}], and that of expm1 is [−1,−(1−2−p)][-1, -(1 - 2^{-p})], as eξ−1e^{\xi} - 1 lies just above −1-1. The first is valid because e230e^{2^{30}} exceeds 2emax⁡+12^{e_{\max}+1}, and the second because e−230e^{-2^{30}} is below the smallest positive Binary at every precision. exp2 and exp10 return exact powers for integer endpoints whose power is representable at the interval’s precision (exp2 of {10}\{10\} is {1024}\{1024\}, exp10 of {3}\{3\} is {1000}\{1000\}); an integer endpoint outside the exponent range keeps the outward-rounded enclosure, so exp2 of {−1073742000}\{-1073742000\} is [0,smallest positive][0, \text{smallest positive}] and of {230}\{2^{30}\} is [largest finite,+∞)[\text{largest finite}, +\infty). The fallback of the total forms is [0,+∞)[0, +\infty) for exp, exp2 and exp10 and [−1,+∞)[-1, +\infty) for expm1.

Interval::ln, Interval::log2, Interval::log10, Interval::log1p, Interval::try_ln, Interval::try_log2, Interval::try_log10, Interval::try_log1p

These return enclosures of ln⁡ξ\ln \xi, log⁡2ξ\log_2 \xi, log⁡10ξ\log_{10} \xi and ln⁡(1+ξ)\ln(1 + \xi) over their domains (0,∞)(0, \infty) and (−1,∞)(-1, \infty).

pub fn Interval::ln(Self) -> Self
pub fn Interval::log2(Self) -> Self
pub fn Interval::log10(Self) -> Self
pub fn Interval::log1p(Self) -> Self
pub fn Interval::try_ln(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_log2(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_log10(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_log1p(Self) -> Result[Self, @arithmetic.ArithmeticError]

When the interval reaches the domain boundary (x‾≤0\underline{x} \le 0, or x‾≤−1\underline{x} \le -1 for log1p) the lower endpoint is −∞-\infty; when it lies entirely outside the domain (x‾≤0\overline{x} \le 0, or x‾<−1\overline{x} < -1 for log1p) the result is Empty. log10 returns exact integers at endpoints 10k10^k, 0≤k≤90 \le k \le 9. The fallback of the total forms is Entire (an endpoint at or below the domain boundary is decided before the kernel runs and is not a failure).

///|
test "exponentials and logarithms" {
  inspect(fmt(iv(0, 1).exp()), content="[1.00000e+0, 2.71829e+0]")
  inspect(fmt(iv(-1, 10).exp2()), content="[5.00000e-1, 1.02400e+3]")
  inspect(fmt(iv(0, 4).ln()), content="[-inf, 1.38630e+0]")
  inspect(fmt(iv(1, 1000).log10()), content="[-0.00000e+0, 3.00000e+0]")
  inspect(iv(-2, -1).ln().is_empty(), content="true")
  // Integer endpoints outside the exponent range keep the outward-rounded enclosure.
  let below = @interval.Interval::from_int(-1073742000, precision=53).exp2()
  inspect(below.lower_bound().to_string(), content="-0")
  inspect(below.upper_bound().to_string(), content="1p-1073741874")
  let above = @interval.Interval::from_int(1 << 30, precision=53).exp2()
  inspect(above.lower_bound().to_string(), content="9007199254740991p1073741771")
  inspect(above.upper_bound().to_string(), content="inf")
}

Interval::pow and Interval::try_pow

pow(x, y) returns an enclosure of {ξη:ξ∈x,η∈y}\{\xi^{\eta} : \xi \in \boldsymbol{x}, \eta \in \boldsymbol{y}\} over the IEEE 1788 domain of pow: ξ>0\xi > 0, or ξ=0\xi = 0 and η>0\eta > 0.

pub fn Interval::pow(Self, Self) -> Self
pub fn Interval::try_pow(Self, Self) -> Result[Self, @arithmetic.ArithmeticError]

Negative parts of the base are ignored (use pown or rootn for negative bases). Since ξη=eηln⁡ξ\xi^\eta = e^{\eta \ln \xi} and ηln⁡ξ\eta \ln \xi is bilinear in (ln⁡ξ,η)(\ln \xi, \eta), the extrema over a box with x‾>0\underline{x} > 0 are at the four corners. When the base reaches 0, ξη→0\xi^\eta \to 0 for η>0\eta > 0 and →+∞\to +\infty for η<0\eta < 0, so the result is extended by 0 or +∞+\infty accordingly. The code also adds the value 1 when the base interval contains 1 or the exponent interval contains 0; it already lies between the corner values, so this changes nothing but is harmless. 0η0^{\eta} for η≤0\eta \le 0 is excluded, so pow([0, 0], y) is Empty when y‾≤0\overline{y} \le 0. The result precision is the larger operand precision. A corner whose power is representable at the result precision, such as 163/4=816^{3/4} = 8, gives that power exactly. The total form falls back to [0,+∞)[0, +\infty).

Interval::rootn and Interval::try_rootn

rootn(x, n) returns an enclosure of the real nn-th roots {ξ1/n}\{\xi^{1/n}\}: for even nn over ξ≥0\xi \ge 0, for odd nn over all reals, and for negative nn the reciprocal of the root.

pub fn Interval::rootn(Self, Int) -> Self
pub fn Interval::try_rootn(Self, Int) -> Result[Self, @arithmetic.ArithmeticError]

rootn(x, 0) and rootn(x, Int min) are Empty; try_rootn(x, 0) is a domain error. rootn(x, 1) is x and rootn(x, 2) is sqrt. The total form is try_rootn with a fallback ([0,+∞)[0, +\infty) for an even degree, Entire for an odd one). For negative nn, try_rootn returns Entire when an odd root’s argument contains 0. Exact roots are returned exactly for every degree, so try_rootn({8}, -3) is {1/2}\{1/2\}.

///|
test "exact powers and roots" {
  let three_quarters = @interval.Interval::exact(
    @binary.Binary::make(@binary.BinCoeff::from_uint64(3UL), -2, 53),
  )
  let p = iv(16, 16).pow(three_quarters)
  inspect(p.lower_bound().to_string() + " " + p.upper_bound().to_string(), content="1p3 1p3")
  let r = iv(8, 8).try_rootn(-3).unwrap()
  inspect(r.lower_bound().to_string() + " " + r.upper_bound().to_string(), content="1p-1 1p-1")
}

Interval::hypot and Interval::try_hypot

hypot returns an enclosure of {ξ2+η2}\{\sqrt{\xi^2 + \eta^2}\}.

pub fn Interval::hypot(Self, Self) -> Self
pub fn Interval::try_hypot(Self, Self) -> Result[Self, @arithmetic.ArithmeticError]

The function is increasing in ∣ξ∣|\xi| and ∣η∣|\eta|, so the result is [RD⁡hypot⁡(mig⁡x,mig⁡y),RU⁡hypot⁡(mag⁡x,mag⁡y)][\operatorname{RD}\operatorname{hypot}(\operatorname{mig}\boldsymbol{x}, \operatorname{mig}\boldsymbol{y}), \operatorname{RU}\operatorname{hypot}(\operatorname{mag}\boldsymbol{x}, \operatorname{mag}\boldsymbol{y})], evaluated on the endpoints of abs(x) and abs(y). The total form falls back to sqrt(sqr(x) + sqr(y)).

Interval::sin, Interval::cos, Interval::tan, Interval::try_sin, Interval::try_cos, Interval::try_tan

These return enclosures of sin⁡\sin, cos⁡\cos and tan⁡\tan over the interval (in radians).

pub fn Interval::sin(Self) -> Self
pub fn Interval::cos(Self) -> Self
pub fn Interval::tan(Self) -> Self
pub fn Interval::try_sin(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_cos(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_tan(Self) -> Result[Self, @arithmetic.ArithmeticError]

Both forms evaluate the binary functions at the endpoints (a point interval) or at the endpoints and the critical points. A critical point kπ/2k\pi/2 inside the interval contributes the extremum ±1\pm 1 of sin/cos (sin reaches +1+1 at k≡1k \equiv 1 and −1-1 at k≡3(mod4)k \equiv 3 \pmod 4, cos reaches +1+1 at k≡0k \equiv 0 and −1-1 at k≡2k \equiv 2); for tan an odd multiple of π/2\pi/2 inside the interval (a pole) makes the result Entire. The set of candidate indices kk is computed from the enclosure of π\pi and can only be too large, which widens but never invalidates the result. Unbounded arguments give [−1,1][-1, 1] (Entire for tan). When the larger endpoint magnitude is at least 2max⁡(65536, 4p)+12^{\max(65536,\, 4p) + 1} the try_ forms return a resource-limit error without evaluating; the total forms return [−1,1][-1, 1] (Entire for tan), the same fallback they use when the certification budget (12 work precisions) is exhausted.

Interval::sinpi, Interval::cospi, Interval::tanpi, Interval::try_sinpi, Interval::try_cospi, Interval::try_tanpi

These return enclosures of sin⁡πξ\sin \pi\xi, cos⁡πξ\cos \pi\xi and tan⁡πξ\tan \pi\xi.

pub fn Interval::sinpi(Self) -> Self
pub fn Interval::cospi(Self) -> Self
pub fn Interval::tanpi(Self) -> Self
pub fn Interval::try_sinpi(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_cospi(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_tanpi(Self) -> Result[Self, @arithmetic.ArithmeticError]

Here the critical points are the exact half-integers k/2k/2, located from the dyadic endpoints without approximating π\pi. tanpi returns a half-unbounded interval when a pole is exactly an endpoint and no other pole lies in the interval (for example [1/2,1][1/2, 1] gives (−∞,0](-\infty, 0], whose upper bound is 0, read as +0+0 by upper_bound (IEEE 1788-2015 12.12.8); tan⁡π\tan \pi is −0-0 in IEEE 754-2019 9.2, but the sign of a stored zero is not part of the interval), Empty for the singleton of a pole, and Entire when a pole lies inside. Unbounded arguments and fallbacks give [−1,1][-1, 1] (Entire for tanpi).

///|
test "trigonometric functions" {
  inspect(fmt(iv(0, 4).sin()), content="[-7.56803e-1, 1.00000e+0]")
  inspect(fmt(iv(0, 4).cos()), content="[-1.00000e+0, 1.00000e+0]")
  inspect(iv(1, 2).tan().is_entire(), content="true")
  let half = @binary.Binary::make(@binary.BinCoeff::one(), -1, 53)
  let x = @interval.Interval::from_bounds(half, @binary.Binary::one(precision=53))
  inspect(fmt(x.sinpi()), content="[-0.00000e+0, 1.00000e+0]")
  inspect(fmt(x.tanpi()), content="[-inf, 0.00000e+0]")
}

Interval::asin, Interval::acos, Interval::atan, Interval::try_asin, Interval::try_acos, Interval::try_atan

These return enclosures of arcsin⁡\arcsin, arccos⁡\arccos (over [−1,1][-1, 1]) and arctan⁡\arctan.

pub fn Interval::asin(Self) -> Self
pub fn Interval::acos(Self) -> Self
pub fn Interval::atan(Self) -> Self
pub fn Interval::try_asin(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_acos(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_atan(Self) -> Result[Self, @arithmetic.ArithmeticError]

asin and atan are increasing and acos is decreasing, so only endpoints are evaluated. atan of an infinite endpoint is ±π/2\pm\pi/2. The fallback of the total forms is [−π/2,π/2][-\pi/2, \pi/2] for atan and asin and [0,π][0, \pi] for acos, with π\pi taken from a constant of at most 64 bits and rounded outward to the interval’s precision, so the fallback itself cannot fail.

Interval::atan2 and Interval::try_atan2

y.atan2(x) returns an enclosure of the angles atan2⁡(η,ξ)∈(−π,π]\operatorname{atan2}(\eta, \xi) \in (-\pi, \pi] of the points (ξ,η)≠(0,0)(\xi, \eta) \ne (0, 0) of the box x×y\boldsymbol{x} \times \boldsymbol{y}.

pub fn Interval::atan2(Self, Self) -> Self
pub fn Interval::try_atan2(Self, Self) -> Result[Self, @arithmetic.ArithmeticError]

The receiver is the ordinate. The result is the hull of the angles at the four corners and at the points where the box meets the axes. When the box crosses the branch cut (x‾<0\underline{x} < 0 and y‾<0≤y‾\underline{y} < 0 \le \overline{y}) the result is [−π,π][-\pi, \pi]. The box {(0,0)}\{(0, 0)\} gives Empty. The total form falls back to [−π,π][-\pi, \pi].

Interval::sinh, Interval::cosh, Interval::tanh, Interval::asinh, Interval::acosh, Interval::atanh, Interval::try_sinh, Interval::try_cosh, Interval::try_tanh, Interval::try_asinh, Interval::try_acosh, Interval::try_atanh

These return enclosures of the hyperbolic functions and their inverses over their domains ([1,∞)[1, \infty) for acosh, (−1,1)(-1, 1) for atanh).

pub fn Interval::sinh(Self) -> Self
pub fn Interval::cosh(Self) -> Self
pub fn Interval::tanh(Self) -> Self
pub fn Interval::asinh(Self) -> Self
pub fn Interval::acosh(Self) -> Self
pub fn Interval::atanh(Self) -> Self
pub fn Interval::try_sinh(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_cosh(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_tanh(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_asinh(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_acosh(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_atanh(Self) -> Result[Self, @arithmetic.ArithmeticError]

cosh has its minimum 1 at 0; the others are monotone. atanh of an interval reaching ±1\pm 1 is unbounded on that side, and an interval whose only point in the domain’s closure is 11 or −1-1 gives Empty. The fallback of the total forms is Entire for sinh, asinh and atanh, [−1,1][-1, 1] for tanh, [1,+∞)[1, +\infty) for cosh and [0,+∞)[0, +\infty) for acosh.

The total forms keep their relative accuracy for a tiny argument, since they are the binary kernels: at 53 bits sinh of {2−300}\{2^{-300}\} is the two-ulp interval [2−300,(1+2−52) 2−300][2^{-300}, (1 + 2^{-52})\,2^{-300}].

///|
test "inverse and hyperbolic functions" {
  let unit = iv(-1, 1)
  inspect(fmt(unit.asin()), content="[-1.57080e+0, 1.57080e+0]")
  inspect(fmt(iv(-2, 2).acos()), content="[-0.00000e+0, 3.14160e+0]")
  inspect(fmt(iv(1, 1).atan2(iv(1, 1))), content="[7.85398e-1, 7.85399e-1]")
  inspect(fmt(unit.cosh()), content="[1.00000e+0, 1.54309e+0]")
  inspect(fmt(unit.atanh()), content="[-inf, inf]")
}

Contexts and flags

IntervalContext::new and IntervalContext::try_new

IntervalContext::new builds a context from a precision and the largest exponent e_max; e_min is 1 - e_max (IEEE 754-2019 3.3).

pub fn IntervalContext::new(precision? : Int, e_max? : Int) -> Self
pub fn IntervalContext::try_new(precision? : Int, e_max? : Int) -> Result[Self, @arithmetic.ArithmeticError]

The defaults are precision 53 and, for e_max, the implementation limit binary_value_e_max of binary, the same as BinaryContext::new given a precision alone (so IntervalContext::new() is not binary64: use binary64() for that). The legality of the pair is decided by BinaryContext::try_new, so binary and interval have one definition of a format: the precision is between 1 and binary_precision_max and e_max is at least 1. An illegal pair aborts new, naming the parameter, and is a domain error for try_new. Before 0.12 e_min was a parameter, any pair with e_min <= e_max was accepted, and the precision had no upper limit.

IntervalContext::with_precision and IntervalContext::with_e_max

These return the same format with another precision, or another largest exponent (and e_min = 1 - e_max); they abort when the result is not legal.

pub fn IntervalContext::with_precision(Self, Int) -> Self
pub fn IntervalContext::with_e_max(Self, Int) -> Self

IntervalContext::binary16, IntervalContext::binary32, IntervalContext::binary64, IntervalContext::binary128

These return the contexts of the IEEE 754 interchange formats: binary16 (p=11p = 11, [−14,15][-14, 15]), binary32 (p=24p = 24, [−126,127][-126, 127]), binary64 (p=53p = 53, [−1022,1023][-1022, 1023]) and binary128 (p=113p = 113, [−16382,16383][-16382, 16383]).

pub fn IntervalContext::binary16() -> Self
pub fn IntervalContext::binary32() -> Self
pub fn IntervalContext::binary64() -> Self
pub fn IntervalContext::binary128() -> Self

IntervalContext::precision, IntervalContext::e_min, IntervalContext::e_max

These return the parameters of a context.

pub fn IntervalContext::precision(Self) -> Int
pub fn IntervalContext::e_min(Self) -> Int
pub fn IntervalContext::e_max(Self) -> Int

IntervalFlags::new, IntervalFlags::combine, IntervalFlags::inexact, IntervalFlags::overflow, IntervalFlags::underflow

IntervalFlags::new returns the flags with nothing raised; combine is their union; the accessors read the fields.

pub fn IntervalFlags::new() -> Self
pub fn IntervalFlags::combine(Self, Self) -> Self
pub fn IntervalFlags::inexact(Self) -> Bool
pub fn IntervalFlags::overflow(Self) -> Bool
pub fn IntervalFlags::underflow(Self) -> Bool

Interval::apply_ctx

apply_ctx rounds an interval outward into a context and reports the flags.

pub fn Interval::apply_ctx(Self, IntervalContext) -> (Self, IntervalFlags)

Each finite nonzero endpoint is rounded outward to the context precision. An endpoint whose rounded exponent exceeds emax⁡e_{\max} overflows: it becomes ∓∞\mp\infty if it is a negative lower or a positive upper endpoint, and the largest finite value of the right sign otherwise (a positive lower endpoint becomes the largest finite value, which is still below it). An endpoint below the normal range is then rounded outward on the subnormal grid 2emin⁡−p+1Z2^{e_{\min} - p + 1}\mathbb{Z}, so a tiny positive upper endpoint becomes the smallest subnormal rather than 0. Rounding twice in the same direction equals rounding once onto the coarser grid, so the endpoints are the directed roundings of the stored ones. Zeros and infinities are kept. Empty gives Empty with no flags. The result has the context precision.

underflow follows IEEE 754 with tininess detected after rounding: it is raised when an endpoint is inexact and its rounding to pp bits with an unbounded exponent range lies below 2emin⁡2^{e_{\min}}, whichever of the two steps lost the bits. With p=4p = 4 and emin⁡=−2e_{\min} = -2, the lower endpoint 2−3(1+2−10)2^{-3}(1 + 2^{-10}) becomes 2−32^{-3}, which is already on the subnormal grid, and raises both inexact and underflow. An exact tiny endpoint raises nothing.

There is no add_ctx or exp_ctx: the operation and the context are composed, (x + y).apply_ctx(ctx). When the operands’ precision is at least the context precision, the double rounding gives the same endpoints as a single outward rounding into the context (see the design page).

Interval::midpoint_ctx

midpoint_ctx is the IEEE 1788 mid operation with the context as the result format.

pub fn Interval::midpoint_ctx(Self, IntervalContext) -> (@binary.Binary, IntervalFlags)

Following IEEE 1788-2015 §12.12.8, Empty gives NaN, Entire gives +0+0, an interval unbounded only above gives the largest finite value of the context, (2−21−p) 2emax⁡(2 - 2^{1-p})\,2^{e_{\max}}, and one unbounded only below gives its negative; none of these raises a flag. A bounded interval gives its exact center rounded once to nearest (ties to even) onto the context’s grid, including the subnormal grid 2emin⁡−p+1Z2^{e_{\min} - p + 1}\mathbb{Z}, so with p=4p = 4, emin⁡=−2e_{\min} = -2 the center 2−6+2−202^{-6} + 2^{-20} gives 2−52^{-5}. A zero center gives +0+0. inexact is set when the result differs from the center and underflow when it is also tiny, as for apply_ctx. A center that rounds beyond emax⁡e_{\max} overflows to an infinity of its sign with overflow and inexact: rounding to nearest maps it to ±∞\pm\infty in IEEE 754, and IEEE 1788 uses that rounding for the bounded case. Only an interval whose endpoints are themselves outside the context’s range can do this.

///|
test "contexts" {
  let ctx = @interval.IntervalContext::new(precision=8, e_max=10)
  let (third, flags) = (iv(1, 1) / iv(3, 3)).apply_ctx(ctx)
  inspect(third.lower_bound().to_string(), content="85p-8")
  inspect(third.upper_bound().to_string(), content="171p-9")
  inspect(flags.inexact(), content="true")
  let (big, big_flags) = iv(5000, 5000).apply_ctx(ctx)
  inspect(fmt(big), content="[2.04000e+3, inf]")
  inspect(big_flags.overflow(), content="true")
  let merged = flags.combine(big_flags)
  inspect(merged.overflow() && merged.inexact(), content="true")
}

Decorated intervals

A decorated operation computes the bare result and the decoration d=min⁡(d1,…,dk,df)d = \min(d_1, \dots, d_k, d_f), where did_i are the operand decorations and dfd_f is the decoration of the operation on these operands (Com when the function is defined and continuous on the whole input box, Trv when the input leaves the domain, as listed below). The minimum is then made canonical (Empty → Trv, unbounded with Com → Dac). Any NaI operand gives NaI.

DecoratedInterval::new

DecoratedInterval::new decorates a bare interval.

pub fn DecoratedInterval::new(Interval, decoration? : Decoration) -> Self

The default decoration is Com. new is setDec of IEEE 1788-2015 11.5.2: the decoration Ill gives NaI for any interval, empty or not (at the precision of the interval, so the result equals DecoratedInterval::nai); otherwise the decoration is made canonical, so new(entire()) is decorated Dac and new(empty()) is decorated Trv, as in IEEE 1788 newDec.

DecoratedInterval::nai and DecoratedInterval::is_nai

nai returns NaI, the result of an invalid decorated construction; is_nai tests for it.

pub fn DecoratedInterval::nai(precision? : Int) -> Self
pub fn DecoratedInterval::is_nai(Self) -> Bool

NaI has decoration Ill and an Empty interval (default precision 53), but it is not Empty: is_empty is false for NaI.

DecoratedInterval::interval and DecoratedInterval::decoration

These return the bare interval and the decoration.

pub fn DecoratedInterval::interval(Self) -> Interval
pub fn DecoratedInterval::decoration(Self) -> Decoration

DecoratedInterval::is_empty, DecoratedInterval::is_entire, DecoratedInterval::is_common_interval, DecoratedInterval::is_singleton, DecoratedInterval::is_member

These predicates apply the bare predicate to the interval and return false for NaI.

pub fn DecoratedInterval::is_empty(Self) -> Bool
pub fn DecoratedInterval::is_entire(Self) -> Bool
pub fn DecoratedInterval::is_common_interval(Self) -> Bool
pub fn DecoratedInterval::is_singleton(Self) -> Bool
pub fn DecoratedInterval::is_member(Self, @binary.Binary) -> Bool

DecoratedInterval::equal, DecoratedInterval::identical, DecoratedInterval::subset, DecoratedInterval::interior, DecoratedInterval::disjoint, DecoratedInterval::less, DecoratedInterval::strict_less, DecoratedInterval::precedes, DecoratedInterval::strict_precedes, DecoratedInterval::overlap

These relations apply the bare relation to the intervals and return false when an operand is NaI, except identical, which is the equality of datums (IEEE 1788-2015 12.3): it is true for two NaI and false for NaI against any other value.

pub fn DecoratedInterval::equal(Self, Self) -> Bool
pub fn DecoratedInterval::identical(Self, Self) -> Bool
pub fn DecoratedInterval::subset(Self, Self) -> Bool
pub fn DecoratedInterval::interior(Self, Self) -> Bool
pub fn DecoratedInterval::disjoint(Self, Self) -> Bool
pub fn DecoratedInterval::less(Self, Self) -> Bool
pub fn DecoratedInterval::strict_less(Self, Self) -> Bool
pub fn DecoratedInterval::precedes(Self, Self) -> Bool
pub fn DecoratedInterval::strict_precedes(Self, Self) -> Bool
pub fn DecoratedInterval::overlap(Self, Self) -> OverlapState?

overlap returns None when an operand is NaI, which has no value for a non-interval-valued operation (IEEE 1788-2015 11.7.2), and Some(state) otherwise.

DecoratedInterval::intersection, DecoratedInterval::convex_hull, DecoratedInterval::cancel_plus, DecoratedInterval::cancel_minus

These apply the bare operation and always lower the decoration to Trv (set operations are not point functions, so no property of a function can be claimed for their results).

pub fn DecoratedInterval::intersection(Self, Self) -> Self
pub fn DecoratedInterval::convex_hull(Self, Self) -> Self
pub fn DecoratedInterval::cancel_plus(Self, Self) -> Self
pub fn DecoratedInterval::cancel_minus(Self, Self) -> Self

DecoratedInterval::add, DecoratedInterval::sub, DecoratedInterval::mul, DecoratedInterval::div, DecoratedInterval::pos, DecoratedInterval::neg, DecoratedInterval::abs, DecoratedInterval::recip, DecoratedInterval::sqr, DecoratedInterval::pown, DecoratedInterval::fma, DecoratedInterval::min, DecoratedInterval::max

The arithmetic operations apply the bare operation; their operation decoration is Com except where the table says otherwise.

pub fn DecoratedInterval::add(Self, Self) -> Self
pub fn DecoratedInterval::sub(Self, Self) -> Self
pub fn DecoratedInterval::mul(Self, Self) -> Self
pub fn DecoratedInterval::div(Self, Self) -> Self
pub fn DecoratedInterval::pos(Self) -> Self
pub fn DecoratedInterval::neg(Self) -> Self
pub fn DecoratedInterval::abs(Self) -> Self
pub fn DecoratedInterval::recip(Self) -> Self
pub fn DecoratedInterval::sqr(Self) -> Self
pub fn DecoratedInterval::pown(Self, Int) -> Self
pub fn DecoratedInterval::fma(Self, Self, Self) -> Self
pub fn DecoratedInterval::min(Self, Self) -> Self
pub fn DecoratedInterval::max(Self, Self) -> Self
OperationOperation decoration
div, recipTrv when the divisor contains 0
pown(x, n)Trv when n<0n < 0 and 0∈x0 \in \boldsymbol{x}
posidentity (IEEE 1788 pos)
othersCom

DecoratedInterval::sqrt, DecoratedInterval::exp, DecoratedInterval::exp2, DecoratedInterval::exp10, DecoratedInterval::expm1, DecoratedInterval::ln, DecoratedInterval::log2, DecoratedInterval::log10, DecoratedInterval::log1p, DecoratedInterval::pow, DecoratedInterval::rootn, DecoratedInterval::hypot

The decorated elementary functions apply the bare total form (there are no decorated try_ forms) and lower the decoration when the input leaves the domain of the function, as listed in the table at the end of this group.

These are the decorated square root, exponentials, logarithms, powers and hypot.

pub fn DecoratedInterval::sqrt(Self) -> Self
pub fn DecoratedInterval::exp(Self) -> Self
pub fn DecoratedInterval::exp2(Self) -> Self
pub fn DecoratedInterval::exp10(Self) -> Self
pub fn DecoratedInterval::expm1(Self) -> Self
pub fn DecoratedInterval::ln(Self) -> Self
pub fn DecoratedInterval::log2(Self) -> Self
pub fn DecoratedInterval::log10(Self) -> Self
pub fn DecoratedInterval::log1p(Self) -> Self
pub fn DecoratedInterval::pow(Self, Self) -> Self
pub fn DecoratedInterval::rootn(Self, Int) -> Self
pub fn DecoratedInterval::hypot(Self, Self) -> Self

DecoratedInterval::sign, DecoratedInterval::ceil, DecoratedInterval::floor, DecoratedInterval::trunc, DecoratedInterval::round_ties_to_even, DecoratedInterval::round_ties_to_away

The interval part is the bare result. The operation decoration is the strongest decoration of 11.2 for the function over the input box, and the result is the minimum of it and the input decoration (11.6, equation 18):

Input box x\boldsymbol{x}Operation decoration
EmptyTrv
the function is not constant on x\boldsymbol{x}Def
constant, and x\boldsymbol{x} unboundedDac
constant, bounded, and x\boldsymbol{x} contains a point of discontinuity of the function on the real lineDac
constant, bounded, and no such point in x\boldsymbol{x}Com

The functions take integer values, so their restriction to x\boldsymbol{x} is continuous exactly when it is constant (dac asks for continuity of the restriction, com for continuity at each point of x\boldsymbol{x}). The points of discontinuity are the integers for ceil and floor, the nonzero integers for trunc, 00 for sign, and the half-integers for the two roundings. For example ceil of the box [1.1,2.0][1.1, 2.0] is [2,2][2, 2] with Dac: the restriction is constant, but 22 is a point of discontinuity of ceil. floor of the same box is [1,2][1, 2] with Def. NaI gives NaI.

pub fn DecoratedInterval::sign(Self) -> Self
pub fn DecoratedInterval::ceil(Self) -> Self
pub fn DecoratedInterval::floor(Self) -> Self
pub fn DecoratedInterval::trunc(Self) -> Self
pub fn DecoratedInterval::round_ties_to_even(Self) -> Self
pub fn DecoratedInterval::round_ties_to_away(Self) -> Self

DecoratedInterval::sqr_rev, DecoratedInterval::abs_rev, DecoratedInterval::pown_rev and DecoratedInterval::cosh_rev

Reverse-mode operations have the trivial decorated version of 11.7.1: NaI if any input (the interval or the prior) is NaI, else the bare result decorated Trv.

pub fn DecoratedInterval::sqr_rev(Self, x? : Self) -> Self
pub fn DecoratedInterval::abs_rev(Self, x? : Self) -> Self
pub fn DecoratedInterval::pown_rev(Self, Int, x? : Self) -> Self
pub fn DecoratedInterval::cosh_rev(Self, x? : Self) -> Self

DecoratedInterval::sin_rev, DecoratedInterval::cos_rev and DecoratedInterval::tan_rev

The trivial decorated version of 11.7.1: NaI if any input (the interval or the prior) is NaI, else the bare result decorated Trv.

pub fn DecoratedInterval::sin_rev(Self, x? : Self) -> Self
pub fn DecoratedInterval::cos_rev(Self, x? : Self) -> Self
pub fn DecoratedInterval::tan_rev(Self, x? : Self) -> Self

DecoratedInterval::pow_rev1

The trivial decorated version of 11.7.1: NaI if any input is NaI, else the bare result decorated Trv.

pub fn DecoratedInterval::pow_rev1(Self, Self, x? : Self) -> Self

DecoratedInterval::mul_rev_to_pair and DecoratedInterval::mul_rev

mul_rev_to_pair follows 12.12.3. If either input is NaI both outputs are NaI. Otherwise, when both are nonempty and 0∉b0 \notin \boldsymbol{b}, the first output is the decorated quotient c/b\boldsymbol{c} / \boldsymbol{b} (the same decoration as /) and the second is Empty with Trv. Every other output, empty or not, is decorated Trv. mul_rev is a reverse-mode operation and has the trivial decorated version of 11.7.1: NaI if any input is NaI, else the bare result decorated Trv.

pub fn DecoratedInterval::mul_rev_to_pair(Self, Self) -> (Self, Self)
pub fn DecoratedInterval::mul_rev(Self, Self, x? : Self) -> Self

DecoratedInterval::sin, DecoratedInterval::cos, DecoratedInterval::tan, DecoratedInterval::sinpi, DecoratedInterval::cospi, DecoratedInterval::tanpi, DecoratedInterval::asin, DecoratedInterval::acos, DecoratedInterval::atan, DecoratedInterval::atan2

These are the decorated trigonometric functions and their inverses.

pub fn DecoratedInterval::sin(Self) -> Self
pub fn DecoratedInterval::cos(Self) -> Self
pub fn DecoratedInterval::tan(Self) -> Self
pub fn DecoratedInterval::sinpi(Self) -> Self
pub fn DecoratedInterval::cospi(Self) -> Self
pub fn DecoratedInterval::tanpi(Self) -> Self
pub fn DecoratedInterval::asin(Self) -> Self
pub fn DecoratedInterval::acos(Self) -> Self
pub fn DecoratedInterval::atan(Self) -> Self
pub fn DecoratedInterval::atan2(Self, Self) -> Self

DecoratedInterval::sinh, DecoratedInterval::cosh, DecoratedInterval::tanh, DecoratedInterval::asinh, DecoratedInterval::acosh, DecoratedInterval::atanh

These are the decorated hyperbolic functions and their inverses.

pub fn DecoratedInterval::sinh(Self) -> Self
pub fn DecoratedInterval::cosh(Self) -> Self
pub fn DecoratedInterval::tanh(Self) -> Self
pub fn DecoratedInterval::asinh(Self) -> Self
pub fn DecoratedInterval::acosh(Self) -> Self
pub fn DecoratedInterval::atanh(Self) -> Self
FunctionOperation decoration Trv when
sqrtx‾<0\underline{x} < 0 (or the input is Empty)
ln, log2, log10x‾≤0\underline{x} \le 0
log1px‾≤−1\underline{x} \le -1
asin, acosx⊈[−1,1]\boldsymbol{x} \not\subseteq [-1, 1]
acoshx‾<1\underline{x} < 1
atanhx‾≤−1\underline{x} \le -1 or x‾≥1\overline{x} \ge 1
rootn(x, n)n=0n = 0, or nn even and x‾<0\underline{x} < 0, or n<0n < 0 and 0∈x0 \in \boldsymbol{x}
pow(x, y)x‾<0\underline{x} < 0, or 0∈x0 \in \boldsymbol{x} and y‾≤0\underline{y} \le 0, or the result is Empty
tanthe result is Entire (a pole may lie inside)
tanpithe result is unbounded (a pole lies in the argument, possibly at an endpoint)
atan2both operands contain 0

All other functions have operation decoration Com. For y.atan2(x) the decoration is Def when the box crosses the branch cut (x‾<0\underline{x} < 0, y‾<0≤y‾\underline{y} < 0 \le \overline{y}: the restriction jumps from −π-\pi to π\pi) and Dac when it touches the cut from above (x‾<0\overline{x} < 0, y‾=0\underline{y} = 0: the restriction is continuous, but atan2 itself is not continuous at those points).

DecoratedInterval::apply_ctx

apply_ctx applies Interval::apply_ctx to the interval and keeps the decoration (made canonical again, so an overflowed Com becomes Dac).

pub fn DecoratedInterval::apply_ctx(Self, IntervalContext) -> (Self, IntervalFlags)

NaI stays NaI, with the context precision.

///|
test "decorated intervals" {
  let x = @interval.DecoratedInterval::new(iv(-1, 4))
  inspect(x.sqrt().decoration(), content="trv")
  inspect(x.exp().decoration(), content="com")
  inspect((x / x).decoration(), content="trv")
  inspect(@interval.DecoratedInterval::new(iv(0, 4)).rootn(-2).decoration(), content="trv")
  let half = @binary.Binary::make(@binary.BinCoeff::one(), -1, 53)
  let pole = @interval.DecoratedInterval::new(
    @interval.Interval::from_bounds(half, @binary.Binary::one(precision=53)),
  )
  inspect(pole.tanpi().decoration(), content="trv")
  let unbounded = @interval.DecoratedInterval::new(@interval.Interval::entire())
  inspect(unbounded.decoration(), content="dac")
  let nai = @interval.DecoratedInterval::nai()
  inspect((x + nai).to_string(), content="[nai]")
  debug_inspect(nai.overlap(x), content="None")
}

Trait implementations

Add, Sub, Mul, Div and Neg for Interval and DecoratedInterval

Interval implements Add, Sub, Mul, Div and Neg; DecoratedInterval implements Add, Sub, Mul and Div. The operators call the methods of the same name.

pub impl Add for Interval
pub impl Sub for Interval
pub impl Mul for Interval
pub impl Div for Interval
pub impl Neg for Interval
pub impl Add for DecoratedInterval
pub impl Sub for DecoratedInterval
pub impl Mul for DecoratedInterval
pub impl Div for DecoratedInterval

Interval::to_string, Interval::output, DecoratedInterval::to_string, DecoratedInterval::output, Decoration::to_string, Decoration::output

Show writes an interval as the portable inf-sup literal of IEEE 1788-2015 13.3 (intervalToText): the text from_string reads.

pub impl Show for Interval
pub fn Interval::to_string(Self) -> String
pub fn Interval::output(Self, &Logger) -> Unit
pub impl Show for DecoratedInterval
pub fn DecoratedInterval::to_string(Self) -> String
pub fn DecoratedInterval::output(Self, &Logger) -> Unit
pub impl Show for Decoration
pub fn Decoration::to_string(Self) -> String
pub fn Decoration::output(Self, &Logger) -> Unit

A nonempty bounded or half-bounded interval prints as [l, u], Empty as [empty], Entire as [entire]; a decorated interval appends _ and the decoration, and NaI prints as [nai]. Each bound is a decimal number rounded outward (the lower bound down, the upper bound up), so the text is a literal of an interval that contains the value (13.3). The digits are the fewest that keep the bound within one unit in the last place of the stored bound at the precision of the interval, so from_string(text, precision=x.precision()) contains x and is wider by at most one unit in the last place at each end. A bound with a binary exponent beyond 4096 in magnitude is written in hexadecimal (0x3p1073741000) because its decimal expansion needs a power of ten of that size; a hexadecimal bound is exact and is a valid literal. A zero bound is written 0, without a sign, whatever sign it has: the literal of [0,0][0, 0] does not carry the signs that lower_bound and upper_bound return (−0-0 and +0+0, 12.12.8), and 13.3 does not ask for them.

///|
test "show" {
  inspect(iv(1, 2).to_string(), content="[1, 2]")
  inspect(@interval.Interval::entire().to_string(), content="[entire]")
  inspect(@interval.DecoratedInterval::new(iv(1, 2)).to_string(), content="[1, 2]_com")
}

Interval::to_exact_string, Interval::from_exact_string, DecoratedInterval::to_exact_string, DecoratedInterval::from_exact_string

IEEE 1788-2015 13.4 intervalToExact and exactToInterval: a text that names the interval itself.

pub fn Interval::to_exact_string(Self) -> String
pub fn Interval::from_exact_string(String, precision? : Int32) -> Result[Self, @arithmetic.ArithmeticError]
pub fn DecoratedInterval::to_exact_string(Self) -> String
pub fn DecoratedInterval::from_exact_string(String, precision? : Int32) -> Result[Self, @arithmetic.ArithmeticError]

The text is [empty], [entire] or [l, u] with the bounds written as hexadecimal numbers (0x1fffffp-3; inf and -inf for an infinite bound), and for a decorated interval _ and the decoration ([nai] for NaI). The bounds are the stored bounds, so from_exact_string(x.to_exact_string(), precision=x.precision()) is identical to x (no signed zero is written, 13.4). from_exact_string reads the text exactly and never widens it. The bounds of the text must be numbers of the format of precision bits, as every stored bound is: a bound with more than precision significant bits (0x1.00000000000001p0 has 57 bits, with any number of trailing zero digits, and is read at precision=57 and refused at 53), a bound beyond the exponent range of the library, or finer than the grid of precision bits below the range floor is refused with a parse error that names the reason, and so is a decimal or malformed bound and a lower bound above the upper bound. Which bounds are representable at all is decided by the converter of IEEE 754-2019 5.12.3 (Binary::from_hex_ctx reports inexact), not by counting digits of the text, so a fractional mantissa (0x1.8p0, 0x.8p1), leading and trailing zero digits and upper case are read. Before 0.12 a wider bound was accepted and kept with the label of its own bit count, because the type could hold such ends; it cannot any more.

///|
test "exact text" {
  let x = iv(1, 2)
  inspect(x.to_exact_string(), content="[0x1p0, 0x1p1]")
  let back = @interval.Interval::from_exact_string(x.to_exact_string()).unwrap()
  assert_true(x.identical(back))
}

Interval::to_midpoint_radius_string, DecoratedInterval::to_midpoint_radius_string

The midpoint-radius view, midpoint +/- radius: the two functions of IEEE 1788-2015 12.12.8 (Interval::midpoint and Interval::radius), numbers of the format of the interval, written in the Binary notation (3p-1 is 3⋅2−13 \cdot 2^{-1}). The radius is taken about the midpoint and covers both bounds, so the printed pair encloses the interval. Before 0.12 Show printed the view; since then it is for reading, not a literal (from_string does not read it), and its cost does not depend on the exponent range: an interval whose bounds have exponents a billion apart is written with numbers of pp bits. An interval with an infinite bound prints as [l, u] of binary numbers, Empty as [empty]; a decorated interval appends _ and the decoration. Before the change of 0.12 the text printed the exact center and half-width, and a number of about 65,000 bits for bounds more than 65,536 places apart.

pub fn Interval::to_midpoint_radius_string(Self) -> String
pub fn DecoratedInterval::to_midpoint_radius_string(Self) -> String

Interval::equal, Interval::not_equal, Interval::to_repr, DecoratedInterval::equal, DecoratedInterval::not_equal, IntervalFlags::equal, IntervalFlags::not_equal

These are the derived Eq and Debug methods of the structures.

pub fn Interval::equal(Self, Self) -> Bool
pub fn Interval::not_equal(Self, Self) -> Bool
pub fn Interval::to_repr(Self) -> @debug.Repr
pub fn DecoratedInterval::equal(Self, Self) -> Bool
pub fn DecoratedInterval::not_equal(Self, Self) -> Bool
pub fn IntervalFlags::equal(Self, Self) -> Bool
pub fn IntervalFlags::not_equal(Self, Self) -> Bool

Decoration::equal, Decoration::not_equal, Decoration::to_repr, OverlapState::equal, OverlapState::not_equal, OverlapState::to_repr

These are the derived Eq and Debug methods of the enums.

pub fn Decoration::equal(Self, Self) -> Bool
pub fn Decoration::not_equal(Self, Self) -> Bool
pub fn Decoration::to_repr(Self) -> @debug.Repr
pub fn OverlapState::equal(Self, Self) -> Bool
pub fn OverlapState::not_equal(Self, Self) -> Bool
pub fn OverlapState::to_repr(Self) -> @debug.Repr

The Eq implementations of Interval and DecoratedInterval are the equal relation of IEEE 1788-2015 (12.12.9), not equality of representation: == compares sets, ignoring precision tags, and on decorated intervals it is false whenever one operand is NaI, so NaI is not equal to itself (as NaN is not), and decorations are ignored. identical is the equality of the datum. to_repr gives the structural Debug form. The Eq of Decoration and OverlapState is the equality of the variants.

@arithmetic.Contains, @arithmetic.Overlaps, @arithmetic.DefinitelyLt, @arithmetic.DefinitelyLe, @arithmetic.MaybeEq

Interval implements the enclosure relation traits of Luna-Flow/arithmetic.

pub impl @arithmetic.Contains for Interval
pub impl @arithmetic.Overlaps for Interval
pub impl @arithmetic.DefinitelyLt for Interval
pub impl @arithmetic.DefinitelyLe for Interval
pub impl @arithmetic.MaybeEq for Interval

Contains::contains(x, y) is y.subset(x) (set inclusion, not the point-taking method). Overlaps::overlaps(x, y) is x‾≤y‾∧y‾≤x‾\underline{x} \le \overline{y} \wedge \underline{y} \le \overline{x}, that is x∩y≠∅\boldsymbol{x} \cap \boldsymbol{y} \ne \emptyset, and MaybeEq::maybe_eq is the same relation read as “the two unknown points may be equal”. DefinitelyLt::definitely_lt(x, y) is x‾<y‾\overline{x} < \underline{y} and DefinitelyLe::definitely_le(x, y) is x‾≤y‾\overline{x} \le \underline{y}: they hold when the order holds for every pair of points. All four are false when an operand is Empty. This differs from disjoint, precedes and strict_precedes, which are true for an Empty operand (IEEE 1788-2015 Table 10.4): overlaps is false where disjoint is true, and definitely_lt is false where strict_precedes is true, so a true answer of the traits is always backed by at least one pair of points. These are the generic interface of Luna-Flow/arithmetic; the interval package spells the standard relations disjoint, precedes and strict_precedes.

Interval::div_checked, Interval::pow_nat_checked, Interval::pow_int_checked

Interval implements DivChecked, PowNatChecked and PowIntChecked; their methods are promoted.

pub impl @arithmetic.DivChecked for Interval
pub impl @arithmetic.PowNatChecked for Interval
pub impl @arithmetic.PowIntChecked for Interval
pub fn Interval::div_checked(Self, Self, @arithmetic.ArithmeticContext) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::pow_nat_checked(Self, UInt, @arithmetic.ArithmeticContext) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::pow_int_checked(Self, Int, @arithmetic.ArithmeticContext) -> Result[Self, @arithmetic.ArithmeticError]

Only ctx.precision is used: the operands are re-rounded to it with with_precision, the operation is applied, and the result is re-rounded outward (see Interval::with_precision). At the operands’ own precision the result is that of the plain operation; at a lower precision it can be wider. They always return Ok. div_checked follows the division rules above (a divisor containing 0 gives an unbounded result, not an error). pow_int_checked uses pown. pow_nat_checked uses binary powering by repeated interval multiplication, which treats the factors as independent: for an argument containing 0 its result is wider than pown. An Empty base gives Empty for every exponent, including 0, as pown does.

///|
test "checked capabilities" {
  let ctx = @lf_arith.ArithmeticContext::new(53)
  let x = iv(-1, 2)
  inspect(fmt(x.pow_int_checked(2, ctx).unwrap()), content="[-0.00000e+0, 4.00000e+0]")
  inspect(fmt(x.pow_nat_checked(2U, ctx).unwrap()), content="[-2.00000e+0, 4.00000e+0]")
  inspect(x.div_checked(iv(-1, 1), ctx).unwrap().is_entire(), content="true")
  inspect(@lf_arith.Contains::contains(iv(0, 9), iv(1, 2)), content="true")
}

Complete public interface

This snapshot is the generated pkg.generated.mbti of the package. It is the authority when prose and interface disagree.

// Generated using `moon info`, DON'T EDIT IT
package "Luna-Flow/floating/interval"

import {
  "Luna-Flow/arithmetic",
  "Luna-Flow/floating/binary",
  "moonbitlang/core/debug",
}

// Values
pub let interval_literal_max_length : Int32

// Errors

// Types and methods
pub struct DecoratedInterval {
  // private fields
}
pub fn DecoratedInterval::abs(Self) -> Self
pub fn DecoratedInterval::abs_rev(Self, x? : Self) -> Self
pub fn DecoratedInterval::acos(Self) -> Self
pub fn DecoratedInterval::acosh(Self) -> Self
pub fn DecoratedInterval::add(Self, Self) -> Self
pub fn DecoratedInterval::apply_ctx(Self, IntervalContext) -> (Self, IntervalFlags)
pub fn DecoratedInterval::asin(Self) -> Self
pub fn DecoratedInterval::asinh(Self) -> Self
pub fn DecoratedInterval::atan(Self) -> Self
pub fn DecoratedInterval::atan2(Self, Self) -> Self
pub fn DecoratedInterval::atan2_rev1(Self, Self, x? : Self) -> Self
pub fn DecoratedInterval::atan2_rev2(Self, Self, x? : Self) -> Self
pub fn DecoratedInterval::atanh(Self) -> Self
pub fn DecoratedInterval::cancel_minus(Self, Self) -> Self
pub fn DecoratedInterval::cancel_plus(Self, Self) -> Self
pub fn DecoratedInterval::ceil(Self) -> Self
pub fn DecoratedInterval::convex_hull(Self, Self) -> Self
pub fn DecoratedInterval::cos(Self) -> Self
pub fn DecoratedInterval::cos_rev(Self, x? : Self) -> Self
pub fn DecoratedInterval::cosh(Self) -> Self
pub fn DecoratedInterval::cosh_rev(Self, x? : Self) -> Self
pub fn DecoratedInterval::cospi(Self) -> Self
pub fn DecoratedInterval::decoration(Self) -> Decoration
pub fn DecoratedInterval::disjoint(Self, Self) -> Bool
pub fn DecoratedInterval::div(Self, Self) -> Self
pub fn DecoratedInterval::equal(Self, Self) -> Bool
pub fn DecoratedInterval::exp(Self) -> Self
pub fn DecoratedInterval::exp10(Self) -> Self
pub fn DecoratedInterval::exp2(Self) -> Self
pub fn DecoratedInterval::expm1(Self) -> Self
pub fn DecoratedInterval::floor(Self) -> Self
pub fn DecoratedInterval::fma(Self, Self, Self) -> Self
pub fn DecoratedInterval::from_exact_string(String, precision? : Int32) -> Result[Self, @arithmetic.ArithmeticError]
pub fn DecoratedInterval::from_string(String, precision? : Int32) -> Result[Self, @arithmetic.ArithmeticError]
pub fn DecoratedInterval::hypot(Self, Self) -> Self
pub fn DecoratedInterval::identical(Self, Self) -> Bool
pub fn DecoratedInterval::interior(Self, Self) -> Bool
pub fn DecoratedInterval::intersection(Self, Self) -> Self
pub fn DecoratedInterval::interval(Self) -> Interval
pub fn DecoratedInterval::is_common_interval(Self) -> Bool
pub fn DecoratedInterval::is_empty(Self) -> Bool
pub fn DecoratedInterval::is_entire(Self) -> Bool
pub fn DecoratedInterval::is_member(Self, @binary.Binary) -> Bool
pub fn DecoratedInterval::is_nai(Self) -> Bool
pub fn DecoratedInterval::is_singleton(Self) -> Bool
pub fn DecoratedInterval::less(Self, Self) -> Bool
pub fn DecoratedInterval::ln(Self) -> Self
pub fn DecoratedInterval::log10(Self) -> Self
pub fn DecoratedInterval::log1p(Self) -> Self
pub fn DecoratedInterval::log2(Self) -> Self
pub fn DecoratedInterval::max(Self, Self) -> Self
pub fn DecoratedInterval::min(Self, Self) -> Self
pub fn DecoratedInterval::mul(Self, Self) -> Self
pub fn DecoratedInterval::mul_rev(Self, Self, x? : Self) -> Self
pub fn DecoratedInterval::mul_rev_to_pair(Self, Self) -> (Self, Self)
pub fn DecoratedInterval::nai(precision? : Int32) -> Self
pub fn DecoratedInterval::neg(Self) -> Self
pub fn DecoratedInterval::new(Interval, decoration? : Decoration) -> Self
pub fn DecoratedInterval::not_equal(Self, Self) -> Bool
pub fn DecoratedInterval::output(Self, &Logger) -> Unit
pub fn DecoratedInterval::overlap(Self, Self) -> OverlapState?
pub fn DecoratedInterval::pos(Self) -> Self
pub fn DecoratedInterval::pow(Self, Self) -> Self
pub fn DecoratedInterval::pow_rev1(Self, Self, x? : Self) -> Self
pub fn DecoratedInterval::pow_rev2(Self, Self, x? : Self) -> Self
pub fn DecoratedInterval::pown(Self, Int32) -> Self
pub fn DecoratedInterval::pown_rev(Self, Int32, x? : Self) -> Self
pub fn DecoratedInterval::precedes(Self, Self) -> Bool
pub fn DecoratedInterval::recip(Self) -> Self
pub fn DecoratedInterval::rootn(Self, Int32) -> Self
pub fn DecoratedInterval::round_ties_to_away(Self) -> Self
pub fn DecoratedInterval::round_ties_to_even(Self) -> Self
pub fn DecoratedInterval::sign(Self) -> Self
pub fn DecoratedInterval::sin(Self) -> Self
pub fn DecoratedInterval::sin_rev(Self, x? : Self) -> Self
pub fn DecoratedInterval::sinh(Self) -> Self
pub fn DecoratedInterval::sinpi(Self) -> Self
pub fn DecoratedInterval::sqr(Self) -> Self
pub fn DecoratedInterval::sqr_rev(Self, x? : Self) -> Self
pub fn DecoratedInterval::sqrt(Self) -> Self
pub fn DecoratedInterval::strict_less(Self, Self) -> Bool
pub fn DecoratedInterval::strict_precedes(Self, Self) -> Bool
pub fn DecoratedInterval::sub(Self, Self) -> Self
pub fn DecoratedInterval::subset(Self, Self) -> Bool
pub fn DecoratedInterval::tan(Self) -> Self
pub fn DecoratedInterval::tan_rev(Self, x? : Self) -> Self
pub fn DecoratedInterval::tanh(Self) -> Self
pub fn DecoratedInterval::tanpi(Self) -> Self
pub fn DecoratedInterval::to_exact_string(Self) -> String
pub fn DecoratedInterval::to_midpoint_radius_string(Self) -> String
pub fn DecoratedInterval::to_string(Self) -> String
pub fn DecoratedInterval::trunc(Self) -> Self
pub impl Add for DecoratedInterval
pub impl Div for DecoratedInterval
pub impl Eq for DecoratedInterval
pub impl Mul for DecoratedInterval
pub impl Show for DecoratedInterval
pub impl Sub for DecoratedInterval

#derive(Compare, Eq, @debug.Debug)
pub(all) enum Decoration {
  Ill
  Trv
  Def
  Dac
  Com
}
pub fn Decoration::equal(Self, Self) -> Bool
pub fn Decoration::not_equal(Self, Self) -> Bool
pub fn Decoration::output(Self, &Logger) -> Unit
pub fn Decoration::to_repr(Self) -> @debug.Repr
pub fn Decoration::to_string(Self) -> String
pub impl Show for Decoration

#derive(@debug.Debug)
pub struct Interval {
  // private fields
}
pub fn Interval::abs(Self) -> Self
pub fn Interval::abs_rev(Self, x? : Self) -> Self
pub fn Interval::acos(Self) -> Self
pub fn Interval::acosh(Self) -> Self
pub fn Interval::add(Self, Self) -> Self
pub fn Interval::apply_ctx(Self, IntervalContext) -> (Self, IntervalFlags)
pub fn Interval::asin(Self) -> Self
pub fn Interval::asinh(Self) -> Self
pub fn Interval::atan(Self) -> Self
pub fn Interval::atan2(Self, Self) -> Self
pub fn Interval::atan2_rev1(Self, Self, x? : Self) -> Self
pub fn Interval::atan2_rev2(Self, Self, x? : Self) -> Self
pub fn Interval::atanh(Self) -> Self
pub fn Interval::cancel_minus(Self, Self) -> Self
pub fn Interval::cancel_plus(Self, Self) -> Self
pub fn Interval::ceil(Self) -> Self
pub fn Interval::convex_hull(Self, Self) -> Self
pub fn Interval::cos(Self) -> Self
pub fn Interval::cos_rev(Self, x? : Self) -> Self
pub fn Interval::cosh(Self) -> Self
pub fn Interval::cosh_rev(Self, x? : Self) -> Self
pub fn Interval::cospi(Self) -> Self
pub fn Interval::disjoint(Self, Self) -> Bool
pub fn Interval::div(Self, Self) -> Self
pub fn Interval::div_checked(Self, Self, @arithmetic.ArithmeticContext) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::empty(precision? : Int32) -> Self
pub fn Interval::entire(precision? : Int32) -> Self
pub fn Interval::equal(Self, Self) -> Bool
pub fn Interval::exact(@binary.Binary, precision? : Int32) -> Self
pub fn Interval::exp(Self) -> Self
pub fn Interval::exp10(Self) -> Self
pub fn Interval::exp2(Self) -> Self
pub fn Interval::expm1(Self) -> Self
pub fn Interval::floor(Self) -> Self
pub fn Interval::fma(Self, Self, Self) -> Self
pub fn Interval::from_bounds(@binary.Binary, @binary.Binary, precision? : Int32) -> Self
pub fn Interval::from_coefficient(@binary.BinCoeff, precision? : Int32, negative? : Bool) -> Self
pub fn Interval::from_double(Double, precision? : Int32) -> Self
pub fn Interval::from_exact_string(String, precision? : Int32) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::from_float(Float, precision? : Int32) -> Self
pub fn Interval::from_int(Int32, precision~ : Int32) -> Self
pub fn Interval::from_midpoint_radius(@binary.Binary, @binary.Binary, precision? : Int32) -> Self
pub fn Interval::from_string(String, precision? : Int32) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::hypot(Self, Self) -> Self
pub fn Interval::identical(Self, Self) -> Bool
pub fn Interval::interior(Self, Self) -> Bool
pub fn Interval::intersection(Self, Self) -> Self
pub fn Interval::is_common_interval(Self) -> Bool
pub fn Interval::is_empty(Self) -> Bool
pub fn Interval::is_entire(Self) -> Bool
pub fn Interval::is_member(Self, @binary.Binary) -> Bool
pub fn Interval::is_singleton(Self) -> Bool
pub fn Interval::less(Self, Self) -> Bool
pub fn Interval::ln(Self) -> Self
pub fn Interval::log10(Self) -> Self
pub fn Interval::log1p(Self) -> Self
pub fn Interval::log2(Self) -> Self
pub fn Interval::lower_bound(Self) -> @binary.Binary
pub fn Interval::magnitude(Self) -> @binary.Binary
pub fn Interval::max(Self, Self) -> Self
pub fn Interval::midpoint(Self) -> @binary.Binary
pub fn Interval::midpoint_ctx(Self, IntervalContext) -> (@binary.Binary, IntervalFlags)
pub fn Interval::mignitude(Self) -> @binary.Binary
pub fn Interval::min(Self, Self) -> Self
pub fn Interval::mul(Self, Self) -> Self
pub fn Interval::mul_rev(Self, Self, x? : Self) -> Self
pub fn Interval::mul_rev_to_pair(Self, Self) -> (Self, Self)
pub fn Interval::neg(Self) -> Self
pub fn Interval::normalized(Self) -> Self
pub fn Interval::not_equal(Self, Self) -> Bool
pub fn Interval::output(Self, &Logger) -> Unit
pub fn Interval::overlap(Self, Self) -> OverlapState
pub fn Interval::pow(Self, Self) -> Self
pub fn Interval::pow_int_checked(Self, Int32, @arithmetic.ArithmeticContext) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::pow_nat_checked(Self, UInt32, @arithmetic.ArithmeticContext) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::pow_rev1(Self, Self, x? : Self) -> Self
pub fn Interval::pow_rev2(Self, Self, x? : Self) -> Self
pub fn Interval::pown(Self, Int32) -> Self
pub fn Interval::pown_rev(Self, Int32, x? : Self) -> Self
pub fn Interval::precedes(Self, Self) -> Bool
pub fn Interval::precision(Self) -> Int32
pub fn Interval::radius(Self) -> @binary.Binary
pub fn Interval::recip(Self) -> Self
pub fn Interval::rootn(Self, Int32) -> Self
pub fn Interval::round_ties_to_away(Self) -> Self
pub fn Interval::round_ties_to_even(Self) -> Self
pub fn Interval::sign(Self) -> Self
pub fn Interval::sin(Self) -> Self
pub fn Interval::sin_rev(Self, x? : Self) -> Self
pub fn Interval::sinh(Self) -> Self
pub fn Interval::sinpi(Self) -> Self
pub fn Interval::sqr(Self) -> Self
pub fn Interval::sqr_rev(Self, x? : Self) -> Self
pub fn Interval::sqrt(Self) -> Self
pub fn Interval::strict_less(Self, Self) -> Bool
pub fn Interval::strict_precedes(Self, Self) -> Bool
pub fn Interval::sub(Self, Self) -> Self
pub fn Interval::subset(Self, Self) -> Bool
pub fn Interval::tan(Self) -> Self
pub fn Interval::tan_rev(Self, x? : Self) -> Self
pub fn Interval::tanh(Self) -> Self
pub fn Interval::tanpi(Self) -> Self
pub fn Interval::to_exact_string(Self) -> String
pub fn Interval::to_midpoint_radius_string(Self) -> String
pub fn Interval::to_repr(Self) -> @debug.Repr
pub fn Interval::to_string(Self) -> String
pub fn Interval::trunc(Self) -> Self
pub fn Interval::try_acos(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_acosh(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_asin(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_asinh(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_atan(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_atan2(Self, Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_atanh(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_cos(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_cosh(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_cospi(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_exact(@binary.Binary, precision? : Int32) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_exp(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_exp10(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_exp2(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_expm1(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_from_bounds(@binary.Binary, @binary.Binary, precision? : Int32) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_from_double(Double, precision? : Int32) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_from_float(Float, precision? : Int32) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_from_midpoint_radius(@binary.Binary, @binary.Binary, precision? : Int32) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_hypot(Self, Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_ln(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_log10(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_log1p(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_log2(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_pow(Self, Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_rootn(Self, Int32) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_sin(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_sinh(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_sinpi(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_tan(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_tanh(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::try_tanpi(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn Interval::upper_bound(Self) -> @binary.Binary
pub fn Interval::width(Self) -> @binary.Binary
pub fn Interval::with_precision(Self, Int32) -> Self
pub impl @arithmetic.Contains for Interval
pub impl @arithmetic.DefinitelyLe for Interval
pub impl @arithmetic.DefinitelyLt for Interval
pub impl @arithmetic.DivChecked for Interval
pub impl @arithmetic.MaybeEq for Interval
pub impl @arithmetic.Overlaps for Interval
pub impl @arithmetic.PowIntChecked for Interval
pub impl @arithmetic.PowNatChecked for Interval
pub impl Add for Interval
pub impl Div for Interval
pub impl Eq for Interval
pub impl Mul for Interval
pub impl Neg for Interval
pub impl Show for Interval
pub impl Sub for Interval

pub struct IntervalContext {
  // private fields
}
pub fn IntervalContext::binary128() -> Self
pub fn IntervalContext::binary16() -> Self
pub fn IntervalContext::binary32() -> Self
pub fn IntervalContext::binary64() -> Self
pub fn IntervalContext::e_max(Self) -> Int32
pub fn IntervalContext::e_min(Self) -> Int32
pub fn IntervalContext::new(precision? : Int32, e_max? : Int32) -> Self
pub fn IntervalContext::precision(Self) -> Int32
pub fn IntervalContext::try_new(precision? : Int32, e_max? : Int32) -> Result[Self, @arithmetic.ArithmeticError]
pub fn IntervalContext::with_e_max(Self, Int32) -> Self
pub fn IntervalContext::with_precision(Self, Int32) -> Self

#derive(Eq)
pub struct IntervalFlags {
  // private fields
}
pub fn IntervalFlags::combine(Self, Self) -> Self
pub fn IntervalFlags::equal(Self, Self) -> Bool
pub fn IntervalFlags::inexact(Self) -> Bool
pub fn IntervalFlags::new() -> Self
pub fn IntervalFlags::not_equal(Self, Self) -> Bool
pub fn IntervalFlags::overflow(Self) -> Bool
pub fn IntervalFlags::underflow(Self) -> Bool

#derive(Eq, @debug.Debug)
pub(all) enum OverlapState {
  BothEmpty
  FirstEmpty
  SecondEmpty
  Before
  Meets
  Overlaps
  Starts
  ContainedBy
  Finishes
  Equals
  After
  MetBy
  OverlappedBy
  StartedBy
  Contains
  FinishedBy
}
pub fn OverlapState::equal(Self, Self) -> Bool
pub fn OverlapState::not_equal(Self, Self) -> Bool
pub fn OverlapState::to_repr(Self) -> @debug.Repr

// Type aliases

// Traits