ball_float API
ball_float is interval arithmetic over BinFloat endpoints. A BallFloat
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).
BallFloatDecorated adds the decorations of IEEE 1788-2015, BallContext
rounds results into a target binary format and reports BallFlags.
Despite the name, the stored representation is the endpoint pair, not a
midpoint and a radius: BallFloat::new(center, radius), center() and
radius() convert to and from the midpoint–radius view. The
tutorial shows typical use; the
design page derives the formulas and proves the
inclusion property.
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
BinFloatendpoints is the binary implementation range ofbin_float, far wider than any interchange format. Use aBallContextto impose a narrower range. - 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 examples on this page use these helpers:
///|
fn iv(lo : Int, hi : Int) -> @ball_float.BallFloat {
@ball_float.BallFloat::from_bounds(
@bin_float.BinFloat::from_int(lo, precision=53),
@bin_float.BinFloat::from_int(hi, precision=53),
)
}
///|
fn fmt(x : @ball_float.BallFloat) -> String {
if x.is_empty() {
return "[empty]"
}
let down = @bin_float.BinaryContext::unbounded(
53,
rounding=@bin_float.BinaryRoundingMode::RoundTowardNegative,
)
let up = @bin_float.BinaryContext::unbounded(
53,
rounding=@bin_float.BinaryRoundingMode::RoundTowardPositive,
)
"[" +
x.lower_bound().to_decimal_string_ctx(6, down).0 +
", " +
x.upper_bound().to_decimal_string_ctx(6, up).0 +
"]"
}
Types
BallFloat
BallFloat is a closed interval with BinFloat endpoints and a precision tag.
pub struct BallFloat {
// 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. The derived Eq compares the stored
representation (endpoints and precision), not the sets; see
BallFloat::set_equal.
BallFloatDecorated
BallFloatDecorated is a BallFloat paired with an IEEE 1788
Decoration, or the special value NaI (not an interval).
pub struct BallFloatDecorated {
// private fields
} derive(Eq)
The decoration is kept canonical: an empty interval always carries Trv, an
unbounded interval never carries Com, and only BallFloatDecorated::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(Eq, @debug.Debug)
For a decorated result of a function evaluated on :
| Constructor | Meaning |
|---|---|
Com | is defined and continuous on , and is bounded |
Dac | is defined and continuous on |
Def | is defined on |
Trv | nothing is known |
Ill | the value is NaI |
Show prints the lower-case IEEE 1788 names com, dac, def, trv, ill.
OverlapState
OverlapState is the result of overlap_state: the IEEE 1788 classification
of the relative position of two intervals.
pub(all) enum OverlapState {
Undefined
BothEmpty
FirstEmpty
SecondEmpty
Before
Meets
OverlapsState
Starts
ContainedBy
Finishes
EqualIntervals
After
MetBy
OverlappedBy
StartedBy
ContainsInterval
FinishedBy
} derive(Eq, @debug.Debug)
The constructors correspond to the IEEE 1788 states bothEmpty,
firstEmpty, secondEmpty, before, meets, overlaps, starts,
containedBy, finishes, equal, after, metBy, overlappedBy,
startedBy, contains and finishedBy; OverlapsState, EqualIntervals
and ContainsInterval carry a suffix only to avoid clashing with method names.
Undefined is returned only by the decorated version when an operand is NaI.
BallContext
BallContext describes a target binary format: a precision in bits and an
exponent range .
pub struct BallContext {
// private fields
}
and follow IEEE 754: a finite nonzero value with is in range when , and it is normal when . See Contexts and flags.
BallFlags
BallFlags records the conditions raised while rounding an interval into a
BallContext.
pub struct BallFlags {
inexact : Bool
overflow : Bool
underflow : Bool
} derive(Eq)
inexact is set when an endpoint changed; overflow when an endpoint was
beyond ; underflow when an endpoint was below the normal range and
its subnormal rounding was inexact. The fields are readable; the accessor
methods are listed under BallFlags.
Construction
BallFloat::new
BallFloat::new builds the interval from a center and a
radius, enlarged so that it is exact at the requested precision.
pub fn BallFloat::new(@bin_float.BinFloat, @bin_float.BinFloat, precision? : Int) -> Self
The default precision is the larger of the precisions of center and
radius. With that precision, the stored interval is
which contains (proof in the
design page). The
endpoints are formed exactly, so they may carry more than
bits. Aborts when center or radius is not finite or when radius is
negative. A precision below 1 is treated as 1.
BallFloat::from_bounds and BallFloat::try_from_bounds
BallFloat::from_bounds builds the interval
from its endpoints, rounded outward to the requested precision.
pub fn BallFloat::from_bounds(@bin_float.BinFloat, @bin_float.BinFloat, precision? : Int) -> Self
pub fn BallFloat::try_from_bounds(@bin_float.BinFloat, @bin_float.BinFloat, 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 BallFloat::empty.
///|
test "from_bounds" {
let two = @bin_float.BinFloat::from_int(2, precision=53)
let three = @bin_float.BinFloat::from_int(3, precision=53)
inspect(fmt(@ball_float.BallFloat::from_bounds(two, three)), content="[2.00000e+0, 3.00000e+0]")
inspect(@ball_float.BallFloat::try_from_bounds(three, two) is Err(_), content="true")
}
BallFloat::exact and BallFloat::try_exact
BallFloat::exact builds the singleton of a finite BinFloat.
pub fn BallFloat::exact(@bin_float.BinFloat, precision? : Int) -> Self
pub fn BallFloat::try_exact(@bin_float.BinFloat, 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 a two-point
interval around x. A non-finite x aborts exact and makes try_exact
return a domain error.
BallFloat::from_int and BallFloat::from_coefficient
BallFloat::from_int and BallFloat::from_coefficient build the singleton of
an integer.
pub fn BallFloat::from_int(Int, precision? : Int) -> Self
pub fn BallFloat::from_coefficient(@bin_float.BinCoeff, precision? : Int, negative? : Bool) -> Self
The default precision is 16. from_coefficient takes a non-negative
BinCoeff magnitude and a separate sign. The integer is first converted to a
BinFloat of bits with round-to-nearest, then embedded with
exact.
BallFloat::from_double, BallFloat::from_float and their try_ forms
These functions build the singleton of the exact binary value of a Double
or Float.
pub fn BallFloat::from_double(Double, precision? : Int) -> Self
pub fn BallFloat::try_from_double(Double, precision? : Int) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::from_float(Float, precision? : Int) -> Self
pub fn BallFloat::try_from_float(Float, precision? : Int) -> Result[Self, @arithmetic.ArithmeticError]
Default precisions are 53 and 24. The conversion to BinFloat 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 .
BallFloat::whole and BallFloat::empty
BallFloat::whole returns Entire and BallFloat::empty returns Empty.
pub fn BallFloat::whole(precision? : Int) -> Self
pub fn BallFloat::empty(precision? : Int) -> Self
The default precision is 53.
Observers
BallFloat::lower_bound and BallFloat::upper_bound
lower_bound and upper_bound return the stored endpoints.
pub fn BallFloat::lower_bound(Self) -> @bin_float.BinFloat
pub fn BallFloat::upper_bound(Self) -> @bin_float.BinFloat
For an unbounded side the endpoint is an infinity. For Empty they return
and respectively, so test is_empty first.
BallFloat::center and BallFloat::radius
center and radius return the midpoint–radius view of a bounded interval.
pub fn BallFloat::center(Self) -> @bin_float.BinFloat
pub fn BallFloat::radius(Self) -> @bin_float.BinFloat
center is and radius is
, both computed exactly (the radius is
rounded up only if it underflows the exponent range), so
is the stored
interval. Both abort on Empty and on unbounded intervals.
BallFloat::midpoint
midpoint returns the center rounded to nearest at the interval’s precision.
pub fn BallFloat::midpoint(Self) -> @bin_float.BinFloat
Entire has midpoint 0. Empty and half-bounded intervals abort.
BallFloat::width and BallFloat::radius_extended
width returns and
radius_extended returns the radius rounded up to the interval’s precision.
pub fn BallFloat::width(Self) -> @bin_float.BinFloat
pub fn BallFloat::radius_extended(Self) -> @bin_float.BinFloat
Both return 0 for Empty and for unbounded intervals instead of aborting.
BallFloat::magnitude and BallFloat::mignitude
magnitude returns and mignitude
returns .
pub fn BallFloat::magnitude(Self) -> @bin_float.BinFloat
pub fn BallFloat::mignitude(Self) -> @bin_float.BinFloat
Both are exact. Empty gives 0; mignitude is 0 when the interval contains 0;
magnitude of an unbounded interval is .
///|
test "observers" {
let x = iv(-3, 5)
inspect(x.center().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")
}
BallFloat::precision, BallFloat::classify and BallFloat::sign
precision returns the precision tag; classify and sign describe the
interval in the vocabulary of scalar floating-point types.
pub fn BallFloat::precision(Self) -> Int
pub fn BallFloat::classify(Self) -> @arithmetic.FpClass
pub fn BallFloat::sign(Self) -> @def.Sign
classify returns NaN for Empty, Finite for a bounded interval and
Infinity for an unbounded one. sign returns Positive when
, Negative when , and Zero otherwise:
Zero means “the interval contains 0”, not “the interval is ”.
sign aborts on Empty.
Shape predicates
is_empty, is_entire, is_bounded, is_common_interval, is_singleton
and contains_zero test the shape of the set.
pub fn BallFloat::is_empty(Self) -> Bool
pub fn BallFloat::is_entire(Self) -> Bool
pub fn BallFloat::is_bounded(Self) -> Bool
pub fn BallFloat::is_common_interval(Self) -> Bool
pub fn BallFloat::is_singleton(Self) -> Bool
pub fn BallFloat::contains_zero(Self) -> Bool
is_bounded and is_common_interval (the IEEE 1788 name) are the same: the
interval is non-empty with two finite endpoints. is_singleton holds when
. contains_zero is false for Empty.
Precision
BallFloat::with_precision
with_precision re-rounds an interval to a new precision without shrinking
it.
pub fn BallFloat::with_precision(Self, Int, @arithmetic.RoundingMode) -> Self
For a bounded interval the center is rounded with mode, the displacement
is added to the radius, and the result is rebuilt as in BallFloat::new. For
an unbounded interval the finite endpoint is rounded outward and mode is
ignored. Empty stays Empty with the new precision. The result always contains
the input, except in the extreme case noted under center when the new
precision exceeds about bits.
BallFloat::normalized
normalized rebuilds a bounded interval from its normalized center and radius
(BinFloat::normalized removes trailing zero bits), and re-rounds the finite
endpoints of an unbounded interval outward.
pub fn BallFloat::normalized(Self) -> Self
The result contains the input.
Set operations
BallFloat::intersection and BallFloat::convex_hull
intersection returns and convex_hull
returns the smallest interval containing .
pub fn BallFloat::intersection(Self, Self) -> Self
pub fn BallFloat::convex_hull(Self, Self) -> Self
Both are computed by endpoint max/min and are exact apart from the final
outward rounding to the larger precision. Disjoint intervals intersect to
Empty; Empty is the identity of convex_hull.
BallFloat::cancel_plus and BallFloat::cancel_minus
cancel_minus(x, y) returns the interval with
, the inverse of addition
used to undo a previous sum; cancel_plus(x, y) is cancel_minus(x, -y).
pub fn BallFloat::cancel_plus(Self, Self) -> Self
pub fn BallFloat::cancel_minus(Self, Self) -> Self
For bounded operands cancel_minus is
, rounded
outward. When that is not an interval (the width of exceeds
the width of ), 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.
BallFloat::contains
contains tests whether a point belongs to the interval.
pub fn BallFloat::contains(Self, @bin_float.BinFloat) -> 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 Trait implementations.
BallFloat::subset, BallFloat::interior, BallFloat::set_equal, BallFloat::disjoint
These test inclusion, inclusion in the interior, equality and disjointness of sets.
pub fn BallFloat::subset(Self, Self) -> Bool
pub fn BallFloat::interior(Self, Self) -> Bool
pub fn BallFloat::set_equal(Self, Self) -> Bool
pub fn BallFloat::disjoint(Self, Self) -> Bool
x.subset(y) is and
x.interior(y) is , where an infinite endpoint counts as interior (so
Entire is interior to itself). Empty is a subset of, interior to and disjoint
from every interval. set_equal ignores the precision tag and the
representation of the endpoints.
BallFloat::overlaps, BallFloat::maybe_eq, BallFloat::separated_from
overlaps tests whether two intervals share a point; maybe_eq is the same
relation read as “the two unknown points may be equal”; separated_from is its
negation.
pub fn BallFloat::overlaps(Self, Self) -> Bool
pub fn BallFloat::maybe_eq(Self, Self) -> Bool
pub fn BallFloat::separated_from(Self, Self) -> Bool
overlaps is false and separated_from is true when an operand is Empty.
BallFloat::definitely_lt, BallFloat::definitely_le, BallFloat::definitely_gt
These hold when the order holds for every pair of points.
pub fn BallFloat::definitely_lt(Self, Self) -> Bool
pub fn BallFloat::definitely_le(Self, Self) -> Bool
pub fn BallFloat::definitely_gt(Self, Self) -> Bool
x.definitely_lt(y) is ,
definitely_le is and definitely_gt is
. All three are false when an operand is Empty
(unlike precedes, which is vacuously true).
BallFloat::less, BallFloat::strictly_less, BallFloat::precedes, BallFloat::strictly_precedes
These are the order relations of IEEE 1788.
pub fn BallFloat::less(Self, Self) -> Bool
pub fn BallFloat::strictly_less(Self, Self) -> Bool
pub fn BallFloat::precedes(Self, Self) -> Bool
pub fn BallFloat::strictly_precedes(Self, Self) -> Bool
For non-empty operands:
| Relation | Condition |
|---|---|
less | and |
strictly_less | (or both ) and (or both ) |
precedes | |
strictly_precedes |
With Empty: less and strictly_less hold only when both are Empty;
precedes and strictly_precedes hold when either is Empty.
BallFloat::overlap_state
overlap_state classifies the relative position of two intervals.
pub fn BallFloat::overlap_state(Self, Self) -> OverlapState
The result is one of the sixteen states of OverlapState
other than Undefined; it is computed from the comparisons of the four
endpoints.
///|
test "relations" {
let a = iv(1, 3)
let b = iv(3, 6)
inspect(a.precedes(b), content="true")
inspect(a.strictly_precedes(b), content="false")
inspect(a.definitely_le(b), content="true")
inspect(a.maybe_eq(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_state(b), content="Meets")
debug_inspect(iv(1, 6).overlap_state(iv(2, 3)), content="ContainsInterval")
}
Arithmetic
BallFloat::add, BallFloat::sub, BallFloat::mul, BallFloat::div
The four basic operations return the outward-rounded hull of
; they
are also available as the operators +, -, *, /.
pub fn BallFloat::add(Self, Self) -> Self
pub fn BallFloat::sub(Self, Self) -> Self
pub fn BallFloat::mul(Self, Self) -> Self
pub fn BallFloat::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). For bounded operands the sign of the operands selects the two products that can be extremal, so at most two (four when both operands contain 0) products are evaluated.
Division follows IEEE 1788: is the hull of .
| Divisor | Result |
|---|---|
| over the endpoint quotients | |
| Empty | |
| Entire | |
| 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 .
///|
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")
}
BallFloat::neg and BallFloat::abs
neg returns and abs returns
.
pub fn BallFloat::neg(Self) -> Self
pub fn BallFloat::abs(Self) -> Self
Both are exact. neg is also the unary operator -.
BallFloat::reciprocal
reciprocal returns with the division rules above.
pub fn BallFloat::reciprocal(Self) -> Self
BallFloat::square and BallFloat::pown
square returns and pown returns for an integer
exponent .
pub fn BallFloat::square(Self) -> Self
pub fn BallFloat::pown(Self, Int) -> Self
Unlike x * x, these use the same point twice, so [-1, 2].square() is
(while x * x 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 ).
///|
test "powers" {
let x = iv(-1, 2)
inspect(fmt(x.square()), 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]")
}
BallFloat::fma
fma(x, y, z) returns an enclosure of with a single
outward rounding.
pub fn BallFloat::fma(Self, Self, Self) -> Self
The 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.
BallFloat::minimum and BallFloat::maximum
minimum and maximum return and
.
pub fn BallFloat::minimum(Self, Self) -> Self
pub fn BallFloat::maximum(Self, Self) -> Self
minimum is and maximum is the analogue with max. An Empty operand
gives 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. The total form (exp_interval, sin_interval,
…) always returns a valid enclosure; when the certified evaluation exhausts
its refinement budget it returns a wider, still valid, interval. The try_
form (try_exp_interval, …) returns Err(ArithmeticError) in that case, with
a certification-failure detail naming the operation, stage and reason.
Except where noted, the try_ forms evaluate each endpoint with the
corresponding bin_float try_*_ctx function rounded toward or
; the total forms either call them or use the certified series of
this package. Both forms return the same set on ordinary inputs; their bounds
may differ by an ulp.
BallFloat::sqrt_interval
sqrt_interval returns .
pub fn BallFloat::sqrt_interval(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.
Exponentials
exp_interval, exp2_interval, exp10_interval and expm1_interval return
enclosures of , , and .
pub fn BallFloat::exp_interval(Self) -> Self
pub fn BallFloat::exp2_interval(Self) -> Self
pub fn BallFloat::exp10_interval(Self) -> Self
pub fn BallFloat::expm1_interval(Self) -> Self
pub fn BallFloat::try_exp_interval(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::try_exp2_interval(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::try_exp10_interval(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::try_expm1_interval(Self) -> Result[Self, @arithmetic.ArithmeticError]
All four are increasing, so the result is
.
exp_interval uses a certified Taylor series with argument halving and never
needs a fallback; for it returns
or .
exp2_interval and exp10_interval evaluate at 96 extra bits
and return exact powers for integer endpoints (for exp10_interval,
exponents ). The total expm1_interval falls back to
.
Logarithms
ln_interval, log2_interval, log10_interval and log1p_interval return
enclosures of , , and over
their domains and .
pub fn BallFloat::ln_interval(Self) -> Self
pub fn BallFloat::log2_interval(Self) -> Self
pub fn BallFloat::log10_interval(Self) -> Self
pub fn BallFloat::log1p_interval(Self) -> Self
pub fn BallFloat::try_ln_interval(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::try_log2_interval(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::try_log10_interval(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::try_log1p_interval(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 the result is Empty. log10_interval
returns exact integers at endpoints , . The total
log1p_interval falls back to Entire.
///|
test "exponentials and logarithms" {
inspect(fmt(iv(0, 1).exp_interval()), content="[1.00000e+0, 2.71829e+0]")
inspect(fmt(iv(-1, 10).exp2_interval()), content="[5.00000e-1, 1.02400e+3]")
inspect(fmt(iv(0, 4).ln_interval()), content="[-inf, 1.38630e+0]")
inspect(fmt(iv(1, 1000).log10_interval()), content="[0.00000e+0, 3.00000e+0]")
inspect(iv(-2, -1).ln_interval().is_empty(), content="true")
}
BallFloat::pow_interval and BallFloat::try_pow_interval
pow_interval(x, y) returns an enclosure of
over the
IEEE 1788 domain of pow: , or and .
pub fn BallFloat::pow_interval(Self, Self) -> Self
pub fn BallFloat::try_pow_interval(Self, Self) -> Result[Self, @arithmetic.ArithmeticError]
Negative parts of the base are ignored (use pown or rootn for negative
bases). The result is the hull of the four corner values, extended by 1 when
the base interval contains 1 or the exponent interval contains 0, by 0 when
the base reaches 0 with positive exponents, and by when the base
reaches 0 with negative exponents. for is excluded, so
pow_interval([0, 0], y) is Empty when . The result
precision is the larger operand precision. The total form falls back to an
evaluation of at 192 extra bits.
BallFloat::rootn and BallFloat::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 BallFloat::rootn(Self, Int) -> Self
pub fn BallFloat::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_interval. The total
form evaluates other degrees through pow_interval with an enclosure of
, so it may be slightly wider than try_rootn. For negative ,
try_rootn returns Entire when an odd root’s argument contains 0.
BallFloat::hypot and BallFloat::try_hypot
hypot returns an enclosure of .
pub fn BallFloat::hypot(Self, Self) -> Self
pub fn BallFloat::try_hypot(Self, Self) -> Result[Self, @arithmetic.ArithmeticError]
The function is increasing in and , so the result is
evaluated at the endpoints of abs(x) and abs(y). The total form falls back
to sqrt_interval(square(x) + square(y)).
Trigonometric functions
sin_interval, cos_interval and tan_interval return enclosures of
, and over the interval (in radians).
pub fn BallFloat::sin_interval(Self) -> Self
pub fn BallFloat::cos_interval(Self) -> Self
pub fn BallFloat::tan_interval(Self) -> Self
pub fn BallFloat::try_sin_interval(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::try_cos_interval(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::try_tan_interval(Self) -> Result[Self, @arithmetic.ArithmeticError]
Both forms reduce each endpoint by a certified enclosure of and
evaluate certified Taylor series. A critical point inside the
interval contributes the extremum of sin/cos; for tan an odd
multiple of inside the interval (a pole) makes the result Entire.
Unbounded arguments give (Entire for tan). When the larger
endpoint magnitude is at least , the total forms return
(Entire) without evaluating and the try_ forms return a
resource-limit error; the total forms use the same fallback when the 12
refinement steps are exhausted.
Trigonometric functions of
sinpi_interval, cospi_interval and tanpi_interval return enclosures of
, and .
pub fn BallFloat::sinpi_interval(Self) -> Self
pub fn BallFloat::cospi_interval(Self) -> Self
pub fn BallFloat::tanpi_interval(Self) -> Self
pub fn BallFloat::try_sinpi_interval(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::try_cospi_interval(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::try_tanpi_interval(Self) -> Result[Self, @arithmetic.ArithmeticError]
Here the critical points are the exact half-integers , located without
approximating . tanpi_interval returns a half-unbounded interval when a
pole is exactly an endpoint (for example gives
), 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_interval()), content="[-7.56803e-1, 1.00000e+0]")
inspect(fmt(iv(0, 4).cos_interval()), content="[-1.00000e+0, 1.00000e+0]")
inspect(iv(1, 2).tan_interval().is_entire(), content="true")
let half = @bin_float.BinFloat::make(@bin_float.BinCoeff::one(), -1, 53)
let x = @ball_float.BallFloat::from_bounds(half, @bin_float.BinFloat::one(precision=53))
inspect(fmt(x.sinpi_interval()), content="[0.00000e+0, 1.00000e+0]")
inspect(fmt(x.tanpi_interval()), content="[-inf, 0.00000e+0]")
}
Inverse trigonometric functions
asin_interval, acos_interval and atan_interval return enclosures of
, (over ) and .
pub fn BallFloat::asin_interval(Self) -> Self
pub fn BallFloat::acos_interval(Self) -> Self
pub fn BallFloat::atan_interval(Self) -> Self
pub fn BallFloat::try_asin_interval(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::try_acos_interval(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::try_atan_interval(Self) -> Result[Self, @arithmetic.ArithmeticError]
asin and atan are increasing and acos is decreasing, so only endpoints
are evaluated. The total atan_interval uses a certified series with a
Machin-formula enclosure of ; asin is computed as
and acos as , at 64
extra bits. atan of an infinite endpoint is .
BallFloat::atan2_interval and BallFloat::try_atan2_interval
y.atan2_interval(x) returns an enclosure of the angles
of the points
of the box .
pub fn BallFloat::atan2_interval(Self, Self) -> Self
pub fn BallFloat::try_atan2_interval(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 (negative , and ranging over negative values and 0) the result is . The box gives Empty. The total form falls back to .
Hyperbolic functions
sinh_interval, cosh_interval, tanh_interval, asinh_interval,
acosh_interval and atanh_interval return enclosures of the hyperbolic
functions and their inverses over their domains ( for acosh,
for atanh).
pub fn BallFloat::sinh_interval(Self) -> Self
pub fn BallFloat::cosh_interval(Self) -> Self
pub fn BallFloat::tanh_interval(Self) -> Self
pub fn BallFloat::asinh_interval(Self) -> Self
pub fn BallFloat::acosh_interval(Self) -> Self
pub fn BallFloat::atanh_interval(Self) -> Self
pub fn BallFloat::try_sinh_interval(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::try_cosh_interval(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::try_tanh_interval(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::try_asinh_interval(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::try_acosh_interval(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::try_atanh_interval(Self) -> Result[Self, @arithmetic.ArithmeticError]
cosh has its minimum 1 at 0; the others are monotone. The total forms
evaluate the defining formulas (,
, , …) in
interval arithmetic at 192 extra bits at each endpoint, so they never fail;
tanh_interval is clipped to . atanh of an interval reaching
is unbounded on that side.
///|
test "inverse and hyperbolic functions" {
let unit = iv(-1, 1)
inspect(fmt(unit.asin_interval()), content="[-1.57080e+0, 1.57080e+0]")
inspect(fmt(iv(-2, 2).acos_interval()), content="[0.00000e+0, 3.14160e+0]")
inspect(fmt(iv(1, 1).atan2_interval(iv(1, 1))), content="[7.85398e-1, 7.85399e-1]")
inspect(fmt(unit.cosh_interval()), content="[1.00000e+0, 1.54309e+0]")
inspect(fmt(unit.atanh_interval()), content="[-inf, inf]")
}
Contexts and flags
BallContext::new and BallContext::try_new
BallContext::new builds a context from a precision and an exponent range.
pub fn BallContext::new(precision? : Int, e_min? : Int, e_max? : Int) -> Self
pub fn BallContext::try_new(precision? : Int, e_min? : Int, e_max? : Int) -> Result[Self, @arithmetic.ArithmeticError]
The defaults are those of binary64: precision 53, ,
. A precision below 1 or aborts new
and is a domain error for try_new.
BallContext::binary32 and BallContext::binary64
These return the contexts of the IEEE 754 binary32 (, ) and binary64 (, ) formats.
pub fn BallContext::binary32() -> Self
pub fn BallContext::binary64() -> Self
BallContext::precision, BallContext::e_min, BallContext::e_max
These return the parameters of a context.
pub fn BallContext::precision(Self) -> Int
pub fn BallContext::e_min(Self) -> Int
pub fn BallContext::e_max(Self) -> Int
BallFlags::new, BallFlags::combine and accessors
BallFlags::new returns the flags with nothing raised; combine is their
union; the accessors read the fields.
pub fn BallFlags::new() -> Self
pub fn BallFlags::combine(Self, Self) -> Self
pub fn BallFlags::inexact(Self) -> Bool
pub fn BallFlags::overflow(Self) -> Bool
pub fn BallFlags::underflow(Self) -> Bool
BallFloat::apply_ctx
apply_ctx rounds an interval outward into a context and reports the flags.
pub fn BallFloat::apply_ctx(Self, BallContext) -> (Self, BallFlags)
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 rounded outward on the subnormal grid , so a tiny positive upper endpoint becomes the smallest subnormal rather than 0. Zeros and infinities are kept. Empty gives Empty with no flags. The result has the context precision.
BallFloat::add_ctx, BallFloat::sub_ctx, BallFloat::mul_ctx, BallFloat::div_ctx
These compute the operation and then apply the context.
pub fn BallFloat::add_ctx(Self, Self, BallContext) -> (Self, BallFlags)
pub fn BallFloat::sub_ctx(Self, Self, BallContext) -> (Self, BallFlags)
pub fn BallFloat::mul_ctx(Self, Self, BallContext) -> (Self, BallFlags)
pub fn BallFloat::div_ctx(Self, Self, BallContext) -> (Self, BallFlags)
x.add_ctx(y, ctx) is (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).
BallFloat::exp_ctx and BallFloat::ln_ctx
exp_ctx and ln_ctx evaluate exp_interval and ln_interval at 32 bits
more than the context precision and then apply the context.
pub fn BallFloat::exp_ctx(Self, BallContext) -> (Self, BallFlags)
pub fn BallFloat::ln_ctx(Self, BallContext) -> (Self, BallFlags)
BallFloat::midpoint_ctx
midpoint_ctx returns the center rounded to nearest at the context precision.
pub fn BallFloat::midpoint_ctx(Self, BallContext) -> (@bin_float.BinFloat, BallFlags)
Subnormal results are rounded on the subnormal grid and raise underflow
when inexact; inexact is set when the center changed. The exponent upper
limit is not applied, so overflow is never raised. Entire gives 0; Empty and
half-bounded intervals abort.
///|
test "contexts" {
let ctx = @ball_float.BallContext::new(precision=8, e_min=-10, e_max=10)
let (third, flags) = iv(1, 1).div_ctx(iv(3, 3), 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.
BallFloatDecorated::new
BallFloatDecorated::new decorates a bare interval.
pub fn BallFloatDecorated::new(BallFloat, decoration? : Decoration) -> Self
The default decoration is Com. The decoration is made canonical, and Ill
is replaced by Trv: new never builds NaI.
BallFloatDecorated::nai and BallFloatDecorated::is_nai
nai returns NaI, the result of an invalid decorated construction; is_nai
tests for it.
pub fn BallFloatDecorated::nai(precision? : Int) -> Self
pub fn BallFloatDecorated::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.
BallFloatDecorated::interval and BallFloatDecorated::decoration
These return the bare interval and the decoration.
pub fn BallFloatDecorated::interval(Self) -> BallFloat
pub fn BallFloatDecorated::decoration(Self) -> Decoration
Decorated predicates and relations
The predicates and relations of BallFloatDecorated apply the bare relation
to the intervals and return false when an operand is NaI.
pub fn BallFloatDecorated::is_empty(Self) -> Bool
pub fn BallFloatDecorated::is_entire(Self) -> Bool
pub fn BallFloatDecorated::is_common_interval(Self) -> Bool
pub fn BallFloatDecorated::is_singleton(Self) -> Bool
pub fn BallFloatDecorated::contains(Self, @bin_float.BinFloat) -> Bool
pub fn BallFloatDecorated::set_equal(Self, Self) -> Bool
pub fn BallFloatDecorated::subset(Self, Self) -> Bool
pub fn BallFloatDecorated::interior(Self, Self) -> Bool
pub fn BallFloatDecorated::disjoint(Self, Self) -> Bool
pub fn BallFloatDecorated::less(Self, Self) -> Bool
pub fn BallFloatDecorated::strictly_less(Self, Self) -> Bool
pub fn BallFloatDecorated::precedes(Self, Self) -> Bool
pub fn BallFloatDecorated::strictly_precedes(Self, Self) -> Bool
pub fn BallFloatDecorated::overlap_state(Self, Self) -> OverlapState
overlap_state returns Undefined when an operand is NaI.
Decorated set operations
intersection, convex_hull, cancel_plus and cancel_minus apply the bare
operation and always lower the decoration to Trv (set operations are not
point functions).
pub fn BallFloatDecorated::intersection(Self, Self) -> Self
pub fn BallFloatDecorated::convex_hull(Self, Self) -> Self
pub fn BallFloatDecorated::cancel_plus(Self, Self) -> Self
pub fn BallFloatDecorated::cancel_minus(Self, Self) -> Self
Decorated arithmetic
The arithmetic operations apply the bare operation; their operation
decoration is Com except where the table says otherwise.
pub fn BallFloatDecorated::add(Self, Self) -> Self
pub fn BallFloatDecorated::sub(Self, Self) -> Self
pub fn BallFloatDecorated::mul(Self, Self) -> Self
pub fn BallFloatDecorated::div(Self, Self) -> Self
pub fn BallFloatDecorated::pos(Self) -> Self
pub fn BallFloatDecorated::neg(Self) -> Self
pub fn BallFloatDecorated::abs(Self) -> Self
pub fn BallFloatDecorated::reciprocal(Self) -> Self
pub fn BallFloatDecorated::square(Self) -> Self
pub fn BallFloatDecorated::pown(Self, Int) -> Self
pub fn BallFloatDecorated::fma(Self, Self, Self) -> Self
pub fn BallFloatDecorated::minimum(Self, Self) -> Self
pub fn BallFloatDecorated::maximum(Self, Self) -> Self
| Operation | Operation decoration |
|---|---|
div, reciprocal | Trv when the divisor contains 0 |
pown(x, n) | Trv when and |
pos | identity (IEEE 1788 pos) |
| others | Com |
Decorated elementary functions
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.
pub fn BallFloatDecorated::sqrt_interval(Self) -> Self
pub fn BallFloatDecorated::exp_interval(Self) -> Self
pub fn BallFloatDecorated::exp2_interval(Self) -> Self
pub fn BallFloatDecorated::exp10_interval(Self) -> Self
pub fn BallFloatDecorated::expm1_interval(Self) -> Self
pub fn BallFloatDecorated::ln_interval(Self) -> Self
pub fn BallFloatDecorated::log2_interval(Self) -> Self
pub fn BallFloatDecorated::log10_interval(Self) -> Self
pub fn BallFloatDecorated::log1p_interval(Self) -> Self
pub fn BallFloatDecorated::pow_interval(Self, Self) -> Self
pub fn BallFloatDecorated::rootn(Self, Int) -> Self
pub fn BallFloatDecorated::hypot(Self, Self) -> Self
pub fn BallFloatDecorated::sin_interval(Self) -> Self
pub fn BallFloatDecorated::cos_interval(Self) -> Self
pub fn BallFloatDecorated::tan_interval(Self) -> Self
pub fn BallFloatDecorated::sinpi_interval(Self) -> Self
pub fn BallFloatDecorated::cospi_interval(Self) -> Self
pub fn BallFloatDecorated::tanpi_interval(Self) -> Self
pub fn BallFloatDecorated::asin_interval(Self) -> Self
pub fn BallFloatDecorated::acos_interval(Self) -> Self
pub fn BallFloatDecorated::atan_interval(Self) -> Self
pub fn BallFloatDecorated::atan2_interval(Self, Self) -> Self
pub fn BallFloatDecorated::sinh_interval(Self) -> Self
pub fn BallFloatDecorated::cosh_interval(Self) -> Self
pub fn BallFloatDecorated::tanh_interval(Self) -> Self
pub fn BallFloatDecorated::asinh_interval(Self) -> Self
pub fn BallFloatDecorated::acosh_interval(Self) -> Self
pub fn BallFloatDecorated::atanh_interval(Self) -> Self
| Function | Operation decoration Trv when |
|---|---|
sqrt_interval | (or the input is Empty) |
ln_interval, log2_interval, log10_interval | |
log1p_interval | |
asin_interval, acos_interval | |
acosh_interval | |
atanh_interval | or |
rootn(x, n) | , or even and |
pow_interval(x, y) | , or and , or the result is Empty |
tan_interval, tanpi_interval | the result is Entire (a pole may lie inside) |
atan2_interval | both operands contain 0 |
All other functions have operation decoration Com. For y.atan2_interval(x)
the decoration is Def when the box crosses the branch cut
(, ) and Dac when it
touches the cut from above (, ).
BallFloatDecorated::apply_ctx
apply_ctx applies BallFloat::apply_ctx to the interval and keeps the
decoration (made canonical again, so an overflowed Com becomes Dac).
pub fn BallFloatDecorated::apply_ctx(Self, BallContext) -> (Self, BallFlags)
NaI stays NaI, with the context precision.
///|
test "decorated intervals" {
let x = @ball_float.BallFloatDecorated::new(iv(-1, 4))
inspect(x.sqrt_interval().decoration(), content="trv")
inspect(x.exp_interval().decoration(), content="com")
inspect((x / x).decoration(), content="trv")
let unbounded = @ball_float.BallFloatDecorated::new(@ball_float.BallFloat::whole())
inspect(unbounded.decoration(), content="dac")
let nai = @ball_float.BallFloatDecorated::nai()
inspect((x + nai).to_string(), content="[nai]")
debug_inspect(nai.overlap_state(x), content="Undefined")
}
Trait implementations
Operators
BallFloat implements Add, Sub, Mul, Div and Neg;
BallFloatDecorated implements Add, Sub, Mul and Div. The operators
call the methods of the same name.
pub impl Add for BallFloat
pub impl Sub for BallFloat
pub impl Mul for BallFloat
pub impl Div for BallFloat
pub impl Neg for BallFloat
pub impl Add for BallFloatDecorated
pub impl Sub for BallFloatDecorated
pub impl Mul for BallFloatDecorated
pub impl Div for BallFloatDecorated
Show
Show writes an interval in an exact text form.
pub impl Show for BallFloat
pub fn BallFloat::to_string(Self) -> String
pub fn BallFloat::output(Self, &Logger) -> Unit
pub impl Show for BallFloatDecorated
pub fn BallFloatDecorated::to_string(Self) -> String
pub fn BallFloatDecorated::output(Self, &Logger) -> Unit
pub impl Show for Decoration
pub fn Decoration::to_string(Self) -> String
pub fn Decoration::output(Self, &Logger) -> Unit
A bounded BallFloat prints as center +/- radius with both numbers in the
exact BinFloat notation (3p-1 is ), so the text denotes
exactly the stored set; an unbounded one prints as [lo, hi], Empty as
[empty]. A decorated interval appends _ and the decoration; NaI prints as
[nai].
///|
test "show" {
inspect(iv(1, 2).to_string(), content="3p-1 +/- 1p-1")
inspect(@ball_float.BallFloat::whole().to_string(), content="[-inf, inf]")
inspect(@ball_float.BallFloatDecorated::new(iv(1, 2)).to_string(), content="3p-1 +/- 1p-1_com")
}
Eq and Debug
pub fn BallFloat::equal(Self, Self) -> Bool
pub fn BallFloat::not_equal(Self, Self) -> Bool
pub fn BallFloat::to_repr(Self) -> @debug.Repr
pub fn BallFloatDecorated::equal(Self, Self) -> Bool
pub fn BallFloatDecorated::not_equal(Self, Self) -> Bool
pub fn BallFlags::equal(Self, Self) -> Bool
pub fn BallFlags::not_equal(Self, Self) -> Bool
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 are derived and compare representations. For
BallFloat and BallFloatDecorated this distinguishes equal sets stored with
different precision tags or endpoint precisions; use set_equal for sets.
to_repr gives the structural Debug form.
@def.Floating
BallFloat implements the Floating trait of def with
classify, sign, precision, with_precision and normalized as
described above, so the generic predicates @def.is_finite (bounded),
@def.is_infinite (unbounded), @def.is_nan (Empty) and @def.is_zero
(sign Zero, that is, contains 0) apply to intervals.
pub impl @def.Floating for BallFloat
Enclosure relations of arithmetic
BallFloat implements the enclosure relation traits of Luna-Flow/arithmetic.
pub impl @arithmetic.Contains for BallFloat
pub impl @arithmetic.Overlaps for BallFloat
pub impl @arithmetic.DefinitelyLt for BallFloat
pub impl @arithmetic.DefinitelyLe for BallFloat
pub impl @arithmetic.MaybeEq for BallFloat
Contains::contains(x, y) is y.subset(x) (set inclusion, not the
point-taking method); the others call the methods of the same name.
Checked capabilities of arithmetic
BallFloat implements DivChecked, PowNatChecked and PowIntChecked; their
methods are promoted.
pub impl @arithmetic.DivChecked for BallFloat
pub impl @arithmetic.PowNatChecked for BallFloat
pub impl @arithmetic.PowIntChecked for BallFloat
pub fn BallFloat::div_checked(Self, Self, @arithmetic.ArithmeticContext) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::pow_nat_checked(Self, UInt, @arithmetic.ArithmeticContext) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::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. 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.
///|
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/ball_float"
import {
"Luna-Flow/arithmetic",
"Luna-Flow/floating/bin_float",
"Luna-Flow/floating/def",
"moonbitlang/core/debug",
}
// Values
// Errors
// Types and methods
pub struct BallContext {
// private fields
}
pub fn BallContext::binary32() -> Self
pub fn BallContext::binary64() -> Self
pub fn BallContext::e_max(Self) -> Int
pub fn BallContext::e_min(Self) -> Int
pub fn BallContext::new(precision? : Int, e_min? : Int, e_max? : Int) -> Self
pub fn BallContext::precision(Self) -> Int
pub fn BallContext::try_new(precision? : Int, e_min? : Int, e_max? : Int) -> Result[Self, @arithmetic.ArithmeticError]
pub struct BallFlags {
inexact : Bool
overflow : Bool
underflow : Bool
} derive(Eq)
pub fn BallFlags::combine(Self, Self) -> Self
pub fn BallFlags::equal(Self, Self) -> Bool
pub fn BallFlags::inexact(Self) -> Bool
pub fn BallFlags::new() -> Self
pub fn BallFlags::not_equal(Self, Self) -> Bool
pub fn BallFlags::overflow(Self) -> Bool
pub fn BallFlags::underflow(Self) -> Bool
pub struct BallFloat {
// private fields
} derive(Eq, @debug.Debug)
pub fn BallFloat::abs(Self) -> Self
pub fn BallFloat::acos_interval(Self) -> Self
pub fn BallFloat::acosh_interval(Self) -> Self
pub fn BallFloat::add(Self, Self) -> Self
pub fn BallFloat::add_ctx(Self, Self, BallContext) -> (Self, BallFlags)
pub fn BallFloat::apply_ctx(Self, BallContext) -> (Self, BallFlags)
pub fn BallFloat::asin_interval(Self) -> Self
pub fn BallFloat::asinh_interval(Self) -> Self
pub fn BallFloat::atan2_interval(Self, Self) -> Self
pub fn BallFloat::atan_interval(Self) -> Self
pub fn BallFloat::atanh_interval(Self) -> Self
pub fn BallFloat::cancel_minus(Self, Self) -> Self
pub fn BallFloat::cancel_plus(Self, Self) -> Self
pub fn BallFloat::center(Self) -> @bin_float.BinFloat
pub fn BallFloat::classify(Self) -> @arithmetic.FpClass
pub fn BallFloat::contains(Self, @bin_float.BinFloat) -> Bool
pub fn BallFloat::contains_zero(Self) -> Bool
pub fn BallFloat::convex_hull(Self, Self) -> Self
pub fn BallFloat::cos_interval(Self) -> Self
pub fn BallFloat::cosh_interval(Self) -> Self
pub fn BallFloat::cospi_interval(Self) -> Self
pub fn BallFloat::definitely_gt(Self, Self) -> Bool
pub fn BallFloat::definitely_le(Self, Self) -> Bool
pub fn BallFloat::definitely_lt(Self, Self) -> Bool
pub fn BallFloat::disjoint(Self, Self) -> Bool
pub fn BallFloat::div(Self, Self) -> Self
pub fn BallFloat::div_checked(Self, Self, @arithmetic.ArithmeticContext) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::div_ctx(Self, Self, BallContext) -> (Self, BallFlags)
pub fn BallFloat::empty(precision? : Int) -> Self
pub fn BallFloat::equal(Self, Self) -> Bool
pub fn BallFloat::exact(@bin_float.BinFloat, precision? : Int) -> Self
pub fn BallFloat::exp10_interval(Self) -> Self
pub fn BallFloat::exp2_interval(Self) -> Self
pub fn BallFloat::exp_ctx(Self, BallContext) -> (Self, BallFlags)
pub fn BallFloat::exp_interval(Self) -> Self
pub fn BallFloat::expm1_interval(Self) -> Self
pub fn BallFloat::fma(Self, Self, Self) -> Self
pub fn BallFloat::from_bounds(@bin_float.BinFloat, @bin_float.BinFloat, precision? : Int) -> Self
pub fn BallFloat::from_coefficient(@bin_float.BinCoeff, precision? : Int, negative? : Bool) -> Self
pub fn BallFloat::from_double(Double, precision? : Int) -> Self
pub fn BallFloat::from_float(Float, precision? : Int) -> Self
pub fn BallFloat::from_int(Int, precision? : Int) -> Self
pub fn BallFloat::hypot(Self, Self) -> Self
pub fn BallFloat::interior(Self, Self) -> Bool
pub fn BallFloat::intersection(Self, Self) -> Self
pub fn BallFloat::is_bounded(Self) -> Bool
pub fn BallFloat::is_common_interval(Self) -> Bool
pub fn BallFloat::is_empty(Self) -> Bool
pub fn BallFloat::is_entire(Self) -> Bool
pub fn BallFloat::is_singleton(Self) -> Bool
pub fn BallFloat::less(Self, Self) -> Bool
pub fn BallFloat::ln_ctx(Self, BallContext) -> (Self, BallFlags)
pub fn BallFloat::ln_interval(Self) -> Self
pub fn BallFloat::log10_interval(Self) -> Self
pub fn BallFloat::log1p_interval(Self) -> Self
pub fn BallFloat::log2_interval(Self) -> Self
pub fn BallFloat::lower_bound(Self) -> @bin_float.BinFloat
pub fn BallFloat::magnitude(Self) -> @bin_float.BinFloat
pub fn BallFloat::maximum(Self, Self) -> Self
pub fn BallFloat::maybe_eq(Self, Self) -> Bool
pub fn BallFloat::midpoint(Self) -> @bin_float.BinFloat
pub fn BallFloat::midpoint_ctx(Self, BallContext) -> (@bin_float.BinFloat, BallFlags)
pub fn BallFloat::mignitude(Self) -> @bin_float.BinFloat
pub fn BallFloat::minimum(Self, Self) -> Self
pub fn BallFloat::mul(Self, Self) -> Self
pub fn BallFloat::mul_ctx(Self, Self, BallContext) -> (Self, BallFlags)
pub fn BallFloat::neg(Self) -> Self
pub fn BallFloat::new(@bin_float.BinFloat, @bin_float.BinFloat, precision? : Int) -> Self
pub fn BallFloat::normalized(Self) -> Self
pub fn BallFloat::not_equal(Self, Self) -> Bool
pub fn BallFloat::output(Self, &Logger) -> Unit
pub fn BallFloat::overlap_state(Self, Self) -> OverlapState
pub fn BallFloat::overlaps(Self, Self) -> Bool
pub fn BallFloat::pow_int_checked(Self, Int, @arithmetic.ArithmeticContext) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::pow_interval(Self, Self) -> Self
pub fn BallFloat::pow_nat_checked(Self, UInt, @arithmetic.ArithmeticContext) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::pown(Self, Int) -> Self
pub fn BallFloat::precedes(Self, Self) -> Bool
pub fn BallFloat::precision(Self) -> Int
pub fn BallFloat::radius(Self) -> @bin_float.BinFloat
pub fn BallFloat::radius_extended(Self) -> @bin_float.BinFloat
pub fn BallFloat::reciprocal(Self) -> Self
pub fn BallFloat::rootn(Self, Int) -> Self
pub fn BallFloat::separated_from(Self, Self) -> Bool
pub fn BallFloat::set_equal(Self, Self) -> Bool
pub fn BallFloat::sign(Self) -> @def.Sign
pub fn BallFloat::sin_interval(Self) -> Self
pub fn BallFloat::sinh_interval(Self) -> Self
pub fn BallFloat::sinpi_interval(Self) -> Self
pub fn BallFloat::sqrt_interval(Self) -> Self
pub fn BallFloat::square(Self) -> Self
pub fn BallFloat::strictly_less(Self, Self) -> Bool
pub fn BallFloat::strictly_precedes(Self, Self) -> Bool
pub fn BallFloat::sub(Self, Self) -> Self
pub fn BallFloat::sub_ctx(Self, Self, BallContext) -> (Self, BallFlags)
pub fn BallFloat::subset(Self, Self) -> Bool
pub fn BallFloat::tan_interval(Self) -> Self
pub fn BallFloat::tanh_interval(Self) -> Self
pub fn BallFloat::tanpi_interval(Self) -> Self
pub fn BallFloat::to_repr(Self) -> @debug.Repr
pub fn BallFloat::to_string(Self) -> String
pub fn BallFloat::try_acos_interval(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::try_acosh_interval(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::try_asin_interval(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::try_asinh_interval(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::try_atan2_interval(Self, Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::try_atan_interval(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::try_atanh_interval(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::try_cos_interval(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::try_cosh_interval(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::try_cospi_interval(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::try_exact(@bin_float.BinFloat, precision? : Int) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::try_exp10_interval(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::try_exp2_interval(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::try_exp_interval(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::try_expm1_interval(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::try_from_bounds(@bin_float.BinFloat, @bin_float.BinFloat, precision? : Int) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::try_from_double(Double, precision? : Int) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::try_from_float(Float, precision? : Int) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::try_hypot(Self, Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::try_ln_interval(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::try_log10_interval(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::try_log1p_interval(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::try_log2_interval(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::try_pow_interval(Self, Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::try_rootn(Self, Int) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::try_sin_interval(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::try_sinh_interval(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::try_sinpi_interval(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::try_tan_interval(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::try_tanh_interval(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::try_tanpi_interval(Self) -> Result[Self, @arithmetic.ArithmeticError]
pub fn BallFloat::upper_bound(Self) -> @bin_float.BinFloat
pub fn BallFloat::whole(precision? : Int) -> Self
pub fn BallFloat::width(Self) -> @bin_float.BinFloat
pub fn BallFloat::with_precision(Self, Int, @arithmetic.RoundingMode) -> Self
pub impl @arithmetic.Contains for BallFloat
pub impl @arithmetic.DefinitelyLe for BallFloat
pub impl @arithmetic.DefinitelyLt for BallFloat
pub impl @arithmetic.DivChecked for BallFloat
pub impl @arithmetic.MaybeEq for BallFloat
pub impl @arithmetic.Overlaps for BallFloat
pub impl @arithmetic.PowIntChecked for BallFloat
pub impl @arithmetic.PowNatChecked for BallFloat
pub impl @def.Floating for BallFloat
pub impl Add for BallFloat
pub impl Div for BallFloat
pub impl Mul for BallFloat
pub impl Neg for BallFloat
pub impl Show for BallFloat
pub impl Sub for BallFloat
pub struct BallFloatDecorated {
// private fields
} derive(Eq)
pub fn BallFloatDecorated::abs(Self) -> Self
pub fn BallFloatDecorated::acos_interval(Self) -> Self
pub fn BallFloatDecorated::acosh_interval(Self) -> Self
pub fn BallFloatDecorated::add(Self, Self) -> Self
pub fn BallFloatDecorated::apply_ctx(Self, BallContext) -> (Self, BallFlags)
pub fn BallFloatDecorated::asin_interval(Self) -> Self
pub fn BallFloatDecorated::asinh_interval(Self) -> Self
pub fn BallFloatDecorated::atan2_interval(Self, Self) -> Self
pub fn BallFloatDecorated::atan_interval(Self) -> Self
pub fn BallFloatDecorated::atanh_interval(Self) -> Self
pub fn BallFloatDecorated::cancel_minus(Self, Self) -> Self
pub fn BallFloatDecorated::cancel_plus(Self, Self) -> Self
pub fn BallFloatDecorated::contains(Self, @bin_float.BinFloat) -> Bool
pub fn BallFloatDecorated::convex_hull(Self, Self) -> Self
pub fn BallFloatDecorated::cos_interval(Self) -> Self
pub fn BallFloatDecorated::cosh_interval(Self) -> Self
pub fn BallFloatDecorated::cospi_interval(Self) -> Self
pub fn BallFloatDecorated::decoration(Self) -> Decoration
pub fn BallFloatDecorated::disjoint(Self, Self) -> Bool
pub fn BallFloatDecorated::div(Self, Self) -> Self
pub fn BallFloatDecorated::equal(Self, Self) -> Bool
pub fn BallFloatDecorated::exp10_interval(Self) -> Self
pub fn BallFloatDecorated::exp2_interval(Self) -> Self
pub fn BallFloatDecorated::exp_interval(Self) -> Self
pub fn BallFloatDecorated::expm1_interval(Self) -> Self
pub fn BallFloatDecorated::fma(Self, Self, Self) -> Self
pub fn BallFloatDecorated::hypot(Self, Self) -> Self
pub fn BallFloatDecorated::interior(Self, Self) -> Bool
pub fn BallFloatDecorated::intersection(Self, Self) -> Self
pub fn BallFloatDecorated::interval(Self) -> BallFloat
pub fn BallFloatDecorated::is_common_interval(Self) -> Bool
pub fn BallFloatDecorated::is_empty(Self) -> Bool
pub fn BallFloatDecorated::is_entire(Self) -> Bool
pub fn BallFloatDecorated::is_nai(Self) -> Bool
pub fn BallFloatDecorated::is_singleton(Self) -> Bool
pub fn BallFloatDecorated::less(Self, Self) -> Bool
pub fn BallFloatDecorated::ln_interval(Self) -> Self
pub fn BallFloatDecorated::log10_interval(Self) -> Self
pub fn BallFloatDecorated::log1p_interval(Self) -> Self
pub fn BallFloatDecorated::log2_interval(Self) -> Self
pub fn BallFloatDecorated::maximum(Self, Self) -> Self
pub fn BallFloatDecorated::minimum(Self, Self) -> Self
pub fn BallFloatDecorated::mul(Self, Self) -> Self
pub fn BallFloatDecorated::nai(precision? : Int) -> Self
pub fn BallFloatDecorated::neg(Self) -> Self
pub fn BallFloatDecorated::new(BallFloat, decoration? : Decoration) -> Self
pub fn BallFloatDecorated::not_equal(Self, Self) -> Bool
pub fn BallFloatDecorated::output(Self, &Logger) -> Unit
pub fn BallFloatDecorated::overlap_state(Self, Self) -> OverlapState
pub fn BallFloatDecorated::pos(Self) -> Self
pub fn BallFloatDecorated::pow_interval(Self, Self) -> Self
pub fn BallFloatDecorated::pown(Self, Int) -> Self
pub fn BallFloatDecorated::precedes(Self, Self) -> Bool
pub fn BallFloatDecorated::reciprocal(Self) -> Self
pub fn BallFloatDecorated::rootn(Self, Int) -> Self
pub fn BallFloatDecorated::set_equal(Self, Self) -> Bool
pub fn BallFloatDecorated::sin_interval(Self) -> Self
pub fn BallFloatDecorated::sinh_interval(Self) -> Self
pub fn BallFloatDecorated::sinpi_interval(Self) -> Self
pub fn BallFloatDecorated::sqrt_interval(Self) -> Self
pub fn BallFloatDecorated::square(Self) -> Self
pub fn BallFloatDecorated::strictly_less(Self, Self) -> Bool
pub fn BallFloatDecorated::strictly_precedes(Self, Self) -> Bool
pub fn BallFloatDecorated::sub(Self, Self) -> Self
pub fn BallFloatDecorated::subset(Self, Self) -> Bool
pub fn BallFloatDecorated::tan_interval(Self) -> Self
pub fn BallFloatDecorated::tanh_interval(Self) -> Self
pub fn BallFloatDecorated::tanpi_interval(Self) -> Self
pub fn BallFloatDecorated::to_string(Self) -> String
pub impl Add for BallFloatDecorated
pub impl Div for BallFloatDecorated
pub impl Mul for BallFloatDecorated
pub impl Show for BallFloatDecorated
pub impl Sub for BallFloatDecorated
pub(all) enum Decoration {
Ill
Trv
Def
Dac
Com
} derive(Eq, @debug.Debug)
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
pub(all) enum OverlapState {
Undefined
BothEmpty
FirstEmpty
SecondEmpty
Before
Meets
OverlapsState
Starts
ContainedBy
Finishes
EqualIntervals
After
MetBy
OverlappedBy
StartedBy
ContainsInterval
FinishedBy
} derive(Eq, @debug.Debug)
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