Correctly rounded binary reductions #
sum decodes every operand exactly, adds in the shared dyadic domain, and rounds once into the
requested destination format. dot does the same with exact products. Source and destination
formats may differ, so the operations cover ordinary uniform reductions and explicit
mixed-precision accumulation with one API.
Exceptional inputs are deterministic:
- the first signaling NaN in traversal order is selected and quieted, ahead of every quiet NaN;
- otherwise the first quiet NaN is selected;
- opposite-signed infinities and
0 * ∞raise invalid, even when a quiet NaN supplies the result; - one infinity sign is preserved; and
- finite inputs are accumulated exactly and rounded once.
NaN payloads are preserved when source and destination formats agree. Cross-format NaNs follow
the ordinary Model.cast policy. An infinite result follows the destination's native overflow
rule, matching casts: IEEE encodings preserve infinity, finite-with-NaN encodings return NaN,
and fully finite encodings return the same-sign maximum. A destination without infinity raises
overflow and inexact. Empty reductions return positive zero. A sum of zeros with the same sign
keeps that sign; cancellation and mixed-sign zeros are negative only under rounding toward
negative infinity. FNUZ destinations use positive zero.
There is deliberately no initial-addend argument. One product plus an addend is already IEEE FMA,
and larger finite algebraic expressions can use ExecFloat.roundOnce. A repeated FMA chain is a
different operation because it rounds every prefix; it agrees with dot only when those
intermediate roundings are exact and the exceptional and signed-zero rules also agree.
The binary reducer and a posit quire share the useful idea “exact products, then one final round,”
but not the same machine model. This reducer uses an unbounded software dyadic accumulator and IEEE
NaN, infinity, signed-zero, and status semantics. A posit quire is a fixed 16n-bit accumulator
with NaR and an explicit coefficient-range condition.
Accumulator state used by the transparent reduction kernels.
The state records exact finite contributions separately from exceptional inputs, so NaN priority and infinity cancellation can be resolved after traversal.
- exact : Numerics.Dyadic
Exact finite contribution accumulated so far.
- sawFiniteTerm : Bool
Whether the reduction has consumed at least one finite term.
- allTermsNegativeZero : Bool
Whether every consumed finite term was a negative zero.
- allTermsPositiveZero : Bool
Whether every consumed finite term was a positive zero.
- positiveInfinity : Bool
Whether a positive infinity has occurred.
- negativeInfinity : Bool
Whether a negative infinity has occurred.
First signaling NaN in traversal order, quieted into the destination format.
First quiet NaN in traversal order, converted into the destination format.
- generatedInvalid : Bool
Whether a product generated an invalid operation such as
0 * ∞.
Instances For
Record the first NaN of each class while preserving signaling-NaN priority.
Instances For
Add one exact finite term to the shared dyadic accumulator.
Instances For
Record an infinity sign without discarding a possible opposing infinity.
Instances For
Consume one summand according to the reduction's exceptional-value policy.
Instances For
Consume one exact product while detecting NaNs, infinities, and 0 * ∞.
Instances For
Accumulate a contiguous dot-product slice without allocating a zipped collection.
index is the first pair to consume and remaining is the number of pairs. The size proofs are
erased after compilation; they make every array access bounds-safe without a default value.
Instances For
Accumulate every pair in two equal-sized arrays in left-to-right traversal order.
Instances For
Resolve exceptional values or round the exact finite result once.
Instances For
Correctly rounded sum of an array.
Every finite source value is decoded exactly, the exact dyadic sum is formed without intermediate
rounding, and the result is rounded once into destination.
Instances For
Value-only projection of sumWithStatus.
Instances For
List entry point for correctly rounded summation.
Instances For
Value-only list entry point for correctly rounded summation.
Instances For
Correctly rounded dot product of two arrays.
Each finite pair is multiplied in the exact dyadic domain, all products are added exactly, and
the result
is rounded once into destination. Unequal lengths are rejected before any arithmetic occurs.
Instances For
Value-only projection of dotWithStatus.
Instances For
List entry point for a correctly rounded dot product.
Instances For
Value-only list entry point for a correctly rounded dot product.