interval API
Purpose
interval is interval arithmetic over Binary endpoints. An Interval
is a closed real interval , 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:
- and round toward and to significant bits. “Rounded outward” means the lower endpoint is rounded with and the upper with .
- 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
Binaryendpoints is the implementation range ofbinary: leading-bit exponents up to , and nonzero magnitudes down to with . Use anIntervalContextto impose a narrower range. - The precision of an interval is between 1 and
binary_precision_max(268,435,456) bits, the limits of aBinaryContext. A constructor that returns a value aborts on a precision outside them and names the limits; thetry_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 . An unbounded interval stores and/or 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 , has no NaN
endpoint, never has or , and
has precision . 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 of a function evaluated on a box :
| Constructor | Meaning |
|---|---|
Com | is non-empty and bounded, is defined and continuous on , and is bounded |
Dac | is non-empty, is defined on and its restriction to is continuous |
Def | is non-empty and is defined on |
Trv | nothing is known |
Ill | the 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 (e_min
is derived, not a parameter).
pub struct IntervalContext {
// private fields
}
and follow IEEE 754: a finite nonzero value with is in range when , and it is normal when . 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 ; 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 bits of the interval
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 that precision, the stored interval is
the exact rounded down and the exact 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 (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 already has at most bits and , the result is the singleton .
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:
| Form | Examples |
|---|---|
| number literals | 3.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?rve | 3.56?1 (), 3.56?1e2 (), 3.560?2u, -10? (half an ulp), -10??u (), -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 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 ; 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
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 ,
the upper endpoint is , or ;
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 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 . 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
when fits in bits and the two-point interval
otherwise. Either way it
contains . 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 .
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
and 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 by lower_bound and as 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 and the upper bound of [-1, 0] is ,
whatever sign of zero the interval was built from; [0, 0] has the representative
. 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 bits (at most significant bits, on the grid of
bits, the band below the range floor included) or an infinity, and its label,
endpoint.precision(), is the precision 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, for every unbounded interval, and otherwise the smallest
number of the precision with , where
is the value midpoint returns: the larger of and
, 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 at 53 bits the
midpoint is and the radius .
Interval::width
width returns , an upper bound
of the exact width. It is NaN for Empty and for unbounded
intervals.
Interval::magnitude and Interval::mignitude
magnitude returns and mignitude
returns .
pub fn Interval::magnitude(Self) -> @binary.Binary
pub fn Interval::mignitude(Self) -> @binary.Binary
For a non-empty interval,
because 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 .
///|
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
. 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 and the upper bound toward , 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 at
53 bits is . Empty stays Empty.
Set operations
Interval::intersection and Interval::convex_hull
intersection returns and convex_hull
returns the smallest interval containing .
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
( and
),
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 with
, 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
.
Indeed , so
forces and
, and this is an interval exactly
when . Because of the outward
rounding, the computed satisfies
. When
, when an operand is unbounded, or when
only is empty, the result is Entire. Empty
with bounded or empty 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 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 , that is
and .
x.interior(y) is : each endpoint comparison is strict, except that two equal
infinite endpoints count as interior (the interior of is
, 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:
| Relation | Set definition | Condition |
|---|---|---|
less | and | and |
strict_less | the same with | (or both ) and (or both ) |
precedes | ||
strict_precedes |
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
; 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:
with taken as 0 in (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 and , the maximum of and ) when either operand has 0 in its interior. The design page proves the sign-case table.
Division follows IEEE 1788: is the hull of .
| Divisor | Result |
|---|---|
| over the endpoint quotients | |
| Empty | |
| Entire, unless | |
| or | half-unbounded (see below), or Entire when |
When the divisor touches 0 at one end, the quotient is unbounded on one side: for example and . A dividend equal to gives for any divisor other than . 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 and abs returns
.
pub fn Interval::neg(Self) -> Self
pub fn Interval::abs(Self) -> Self
abs is when , when
, and otherwise.
Both are exact. neg is also the unary operator -.
Interval::recip
recip returns with the division rules above.
pub fn Interval::recip(Self) -> Self
Interval::sqr and Interval::pown
sqr returns and pown returns for an integer
exponent .
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
(while x * x is ): sqr is
.
pown evaluates the monotone pieces of at the endpoints with directed
rounding: odd positive powers are increasing; even positive powers decrease
then increase, with minimum 0 when ; negative powers
have a pole at 0. pown(x, 0) is for every non-empty x; Empty stays
Empty. pown(x, n) with returns Empty for , a
half-unbounded interval when 0 is an endpoint, and for 0 in the interior
Entire (odd ) or (even
). As a shortcut, with 0 in the interior returns Entire even
for even ; 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 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 before the final rounding, so the result is never wider
than x * y + z.
Interval::min and Interval::max
min and max return and
.
pub fn Interval::min(Self, Self) -> Self
pub fn Interval::max(Self, Self) -> Self
min is and max is the analogue with max: 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 , or
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 is nondecreasing, so the result is
. The values are integers (or , ,
), so the result is exact: nothing is rounded, the precision tag is kept,
and a zero bound is stored as . The function of is
(for sign, ). 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 ,
where is the receiver and the prior is the
optional last argument (default Entire). The hull is taken after meeting the
preimage with , not before: for ,
sqr_rev is and with the prior it is , while
.
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:
| Function | Preimage of |
|---|---|
sqr_rev | , the endpoints of the roots rounded outward |
abs_rev | , exact |
cosh_rev | |
pown_rev, | if , else empty ( for every ) |
pown_rev, even and positive | |
pown_rev, odd and positive | , one interval (: ) |
pown_rev, even and negative | with : the -th root of , the upper end of bounding from below and the lower end from above |
pown_rev, odd and negative | the positive part of gives positive and the negative part gives negative , each by with the pole 0 excluded |
An Empty , or a 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 is not in the
domain, so the component that ends at 0 (when is unbounded above
for an even , or reaches the pole) is open there: with and the set is and the prior
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 for the receiver and the optional prior (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 , and , the preimage of sin_rev is ; cos_rev and tan_rev are analogous
(tan_rev: , a
bound at giving the pole , which is not in the domain).
With the default prior the result is Entire for every that meets the
range of the function; outside gives Empty for sin_rev and
cos_rev, and (tan_rev: 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
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
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 inside the limit the cost grows with like the cost of the
forward functions of the
trigonometric functions section,
the working precision following .
///|
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
for the optional prior (default Entire); the receiver is the exponent interval
. is defined for and for with (value 0).
pub fn Interval::pow_rev1(Self, Self, x? : Self) -> Self
For , means , so
the set is with ,
the set division of mul_rev in logarithm
coordinates, plus the point 0 when and has a positive point.
Every end of a piece is , 0, 1 or infinite. The ends that are not
attained are open: 0 (from , unless the zero part closes it) and 1 (the limit of a
quotient by an unbounded ); a prior that only touches such an end does not meet the
set. For example pow_rev1([1, +inf), [2, +inf)) is , so with the prior the
result is Empty, and pow_rev1([-1, 1], [0.5, 2]) is , so with the prior
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
is classified from the structure of and (no squaring): it is a float
candidate (dyadic), a rational that is not a float (for example ), 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 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 is decided at once because the sign of 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
for the optional prior (default Entire); the receiver is the base interval
and the unknown is the exponent. is defined for and for
with (value 0).
pub fn Interval::pow_rev2(Self, Self, x? : Self) -> Self
For , means , so the
set is with and
, the set division of
mul_rev in logarithm coordinates, plus
when and (the base 0). The base 1 is the
branch ” in the divisor”: if and every exponent qualifies,
and if and there is none. Every end of a piece is
, 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 (and ); a prior that
only touches such an end does not meet the set. For example pow_rev2([2, +inf), [2, 4]) is
, so with the prior the result is Empty, while with the
end 0 is attained and the result is .
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
of an end is classified from the structure of and : it is rational iff
and 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
); 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
:
the receiver is the abscissa interval and the unknown is the ordinate .
a.atan2_rev2(c, x?) is the hull of
:
the receiver is the ordinate interval and the unknown is the abscissa . The optional prior
defaults to Entire.
pub fn Interval::atan2_rev1(Self, Self, x? : Self) -> Self
pub fn Interval::atan2_rev2(Self, Self, x? : Self) -> Self
is defined on the plane minus the origin, with the range (Table 9.1, footnote f): the angle is attained on the half-line , , and is never attained. With the set is the projection of the sector 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 has no point in (for example ), when an operand or the prior is Empty, and for the abscissa (Rev1) or the ordinate (Rev2) when misses the angles (Rev1) or and (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 (Rev1) or (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 is
below or above a multiple of is decided exactly ( 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 and the set
has zero, one or two connected components, and is not always closed
(). 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 for two. The two closures can
share an endpoint: gives ([-inf, 0], [0, +inf]). An Empty operand gives
(Empty, Empty). The receiver is and the argument is
, as in the standard’s mulRevToPair(b, c).
mul_rev(b, c, x?) is with the default
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
, and 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
counts as open, so mul_rev([1, +inf), [1, 1], x=[-1, 0]) is
Empty (the set is ) and with it is
. 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 returns an interval containing , where is the domain of ; points of outside are ignored and the result is Empty when 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 or , 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 .
pub fn Interval::sqrt(Self) -> Self
The endpoints are the downward and upward square roots at the interval’s
precision. Empty when . 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 , , and .
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
.
For the enclosure of all four is
; for that of exp, exp2
and exp10 is , and that of expm1 is
, as lies just above . The first is valid
because exceeds , and the second because
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 is , exp10 of is
); an integer endpoint outside the exponent range keeps the
outward-rounded enclosure, so exp2 of is
and of is
. The fallback of the total forms is
for exp, exp2 and exp10 and 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 , , and over their domains and .
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 (, or
for log1p) the lower endpoint is ; when it
lies entirely outside the domain (, or
for log1p) the result is Empty. log10
returns exact integers at endpoints , . 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
over the
IEEE 1788 domain of pow: , or and .
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 and is bilinear in
, the extrema over a box with are at the
four corners. When the base reaches 0, for and
for , so the result is extended by 0 or
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. for
is excluded, so pow([0, 0], y) is Empty when .
The result precision is the larger operand precision. A corner whose power is
representable at the result precision, such as , gives that
power exactly. The total
form falls back to .
Interval::rootn and Interval::try_rootn
rootn(x, n) returns an enclosure of the real -th roots
: for even over , for odd over all reals,
and for negative 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 ( for an even degree, Entire
for an odd one). For negative , 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 .
///|
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 .
pub fn Interval::hypot(Self, Self) -> Self
pub fn Interval::try_hypot(Self, Self) -> Result[Self, @arithmetic.ArithmeticError]
The function is increasing in and , so the result is
,
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 , and 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 inside the
interval contributes the extremum of sin/cos (sin reaches
at and at , cos reaches at
and at ); for tan an odd multiple of
inside the interval (a pole) makes the result Entire. The set of candidate
indices is computed from the enclosure of and can only be too large,
which widens but never invalidates the result. Unbounded arguments give
(Entire for tan). When the larger endpoint magnitude is at least
the try_ forms return a resource-limit error
without evaluating; the total forms return (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 , and .
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 , located from the
dyadic endpoints without approximating . tanpi returns a
half-unbounded interval when a pole is exactly an endpoint and no other pole
lies in the interval (for example gives , whose upper
bound is 0, read as by upper_bound (IEEE 1788-2015 12.12.8); is
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 (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 , (over ) and .
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 . The fallback of
the total forms is for atan and asin and for
acos, with 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
of the points
of the box .
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 ( and ) the result is . The box gives Empty. The total form falls back to .
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 ( for acosh, 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 is unbounded on that side, and an interval whose
only point in the domain’s closure is or gives Empty. The fallback of
the total forms is Entire for sinh, asinh and atanh, for
tanh, for cosh and for acosh.
The total forms keep their relative accuracy for a tiny argument, since they
are the binary kernels: at 53 bits sinh of is
the two-ulp interval .
///|
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 (, ), binary32 (, ), binary64 (, ) and binary128 (, ).
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 overflows: it becomes 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 , 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 bits with an
unbounded exponent range lies below , whichever of the two steps
lost the bits. With and , the lower endpoint
becomes , 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 , an
interval unbounded only above gives the largest finite value of the context,
, 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 , so with
, the center gives . A zero
center gives . 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 overflows to an infinity of its sign with overflow and
inexact: rounding to nearest maps it to 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
, where are the operand decorations and
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
| Operation | Operation decoration |
|---|---|
div, recip | Trv when the divisor contains 0 |
pown(x, n) | Trv when and |
pos | identity (IEEE 1788 pos) |
| others | Com |
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 | Operation decoration |
|---|---|
| Empty | Trv |
| the function is not constant on | Def |
| constant, and unbounded | Dac |
| constant, bounded, and contains a point of discontinuity of the function on the real line | Dac |
| constant, bounded, and no such point in | Com |
The functions take integer values, so their restriction to is
continuous exactly when it is constant (dac asks for continuity of the
restriction, com for continuity at each point of ). The points
of discontinuity are the integers for ceil and floor, the nonzero integers
for trunc, for sign, and the half-integers for the two roundings. For
example ceil of the box is with Dac: the restriction
is constant, but is a point of discontinuity of ceil. floor of the same
box is 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 , the first
output is the decorated quotient (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
| Function | Operation decoration Trv when |
|---|---|
sqrt | (or the input is Empty) |
ln, log2, log10 | |
log1p | |
asin, acos | |
acosh | |
atanh | or |
rootn(x, n) | , or even and , or and |
pow(x, y) | , or and , or the result is Empty |
tan | the result is Entire (a pole may lie inside) |
tanpi | the result is unbounded (a pole lies in the argument, possibly at an endpoint) |
atan2 | both 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
(, : the restriction
jumps from to ) and Dac when it touches the cut from above
(, : 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 does not carry the signs that lower_bound and upper_bound return ( and , 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
). 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 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
, that is
, and MaybeEq::maybe_eq is
the same relation read as “the two unknown points may be equal”.
DefinitelyLt::definitely_lt(x, y) is and
DefinitelyLe::definitely_le(x, y) is : 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