Correctness of IEEE exception status #
The executable status kernels in Status.Runtime satisfy cross-flag invariants and
operation-level specifications. Import BinaryInterchange.Status for the combined public
interface.
The rounding-status classifiers compare an exact dyadic or scaled rational with the supplied
rounded value. Operation wrappers compute that exact witness alongside the value-only operation.
This file proves cross-flag invariants, preservation of the ordinary result, real-order tininess
boundaries, and operation-specific invalid and divide-by-zero conditions. On a positive finite
input, square root raises inexact exactly when its delivered value is not the real square root
(sqrt_inexact_iff).
Constructors and rounding-status invariants #
The direct result classifier recognizes exactly finite zero and subnormal encodings.
The underflow midpoint is exactly halfway between the unbounded-grid predecessor and the smallest normal value.
Both gaps are one 2^(minSubnormalExponent - 2) step. The equalities pin down the
quarter-subnormal offset used by nearest-even and rule out an off-by-one significand or exponent
in the three executable boundary constants.
Real-order specification of after-rounding dyadic tininess.
An already tiny encoding is accepted immediately. Otherwise both nearest modes use the underflow
midpoint, rounding toward zero uses the smallest normal, and a directed mode uses either the
unbounded-grid predecessor or the smallest normal according to whether it rounds this sign away
from zero. This theorem is the semantic boundary for the executable comparisons in
dyadicIsTinyAfterRounding.
Nearest-away rounding detects tininess at the same boundary as nearest-even rounding.
Nearest-away rounding detects tininess at the same boundary as nearest-even rounding.
Real-order specification of after-rounding tininess for scaled rationals.
The denominator premise excludes the malformed representation for which the executable comparator
returns none. For every valid rational, the optimized leading-exponent comparison has the same
mode-sensitive boundaries as the dyadic classifier above.
The dyadic and scaled-rational tininess classifiers agree when the rational has denominator one.
This bridge lets operation proofs choose the representation natural to their exact arithmetic without creating two notions of IEEE underflow.
outcomeWithInvalid preserves its supplied floating-point value.
outcomeWithInvalid records its supplied invalid-operation condition.
outcomeWithInvalid never raises divide-by-zero.
outcomeWithInvalid carries the exceptional-result ternary convention .eq.
This is a convention for NaNs, exact infinities, and placeholders, not a statement that the value equals an exact real result.
A dyadic rounding outcome delivers the value it was given.
The status of a dyadic rounding outcome is dyadicRoundingStatus.
The ternary value of a dyadic rounding outcome is dyadicTernary.
A scaled rational rounding outcome delivers the value it was given.
The status of a scaled rational rounding outcome is rationalRoundingStatusScaled.
The ternary value of a scaled rational rounding outcome is rationalTernaryScaled.
Ternary values #
A finite value denotes the real value of its decoded dyadic.
For a finite delivery, the dyadic ternary value is the real comparison with the exact value.
A finite delivery has the dyadic ternary value .lt exactly when it is below the exact one.
A finite delivery has the dyadic ternary value .eq exactly when it equals the exact value.
A finite delivery has the dyadic ternary value .gt exactly when it is above the exact one.
A non-finite delivery has the ternary value given by the sign of the exact value, the overflow
convention of dyadicTernary.
For a finite delivery and a nonzero denominator, the rational ternary value is the real comparison with the exact signed rational.
A finite delivery has the rational ternary value .lt exactly when it is below the rational.
A finite delivery has the rational ternary value .eq exactly when it equals the rational.
A finite delivery has the rational ternary value .gt exactly when it is above the rational.
A non-finite delivery has the rational ternary value given by the sign of the exact rational, the
overflow convention of rationalTernaryScaled.
With denominator one, the rational ternary value is the dyadic ternary value of the same exact number, so operations may use either representation of their exact result.
The exact-infinity ternary value is .eq exactly for the infinity itself.
Any delivery other than the exact infinity itself has the exact-infinity ternary value .lt for
+∞ and .gt for -∞. For a saturated finite value this is the order, and for the overflow NaN
of a format without infinities it is the convention of IEEEOutcome.ternary.
A finite delivery is compared with the radicand through the exact square of its decoding.
A non-finite delivery has the square-root ternary value .gt.
For a finite nonnegative delivery and a nonnegative radicand, the square-root ternary value is the real comparison of the delivered value with the exact square root.
After-rounding dyadic underflow implies inexactness.
Dyadic rounding reports overflow when rounding crosses the format's overflow threshold or when the supplied rounded result is an infinity.
For a finite result, dyadic overflow is exactly the exact-value overflow classification.
Dyadic rounding overflow always raises inexact.
A dyadic rounding result cannot simultaneously signal overflow and underflow.
After-rounding scaled rational underflow implies inexactness.
Scaled rational rounding reports overflow when rounding crosses the format's overflow threshold or when the supplied rounded result is an infinity.
For a finite result, scaled rational overflow is exactly the exact-value overflow classification.
Scaled rational overflow always raises inexact.
Scaled rational rounding cannot signal overflow and underflow together.
Dyadic rounding is invalid exactly for an unclassified non-finite, non-infinite result.
A finite dyadic rounding result cannot raise invalid.
Rounding an exact dyadic never raises divideByZero.
Scaled rational rounding is invalid exactly for an unclassified non-finite, non-infinite result.
A finite scaled rational rounding result cannot raise invalid.
Rounding an exact scaled rational never raises divideByZero.
Result projection #
Addition with status := true delivers the value of addition in the same direction.
Subtraction with status := true delivers the value of subtraction in the same direction.
Multiplication with status := true delivers the value of multiplication in the same direction.
Division with status := true delivers the value of division in the same direction.
FMA with status := true delivers the value of FMA in the same direction.
Square root with status := true delivers the value of square root in the same direction.
Operation-specific exceptional status #
Finite addition reports its dyadic rounding status and ternary value.
Complete invalid-status classification for addition.
Finite operands take the rounded result's classification. Exceptional operands raise invalid exactly for a signaling NaN or opposite-signed infinities when no NaN was supplied.
Finite multiplication reports its dyadic rounding status and ternary value.
Complete invalid-status classification for multiplication.
Finite operands take the rounded result's classification. Exceptional operands raise invalid exactly for a signaling NaN or an infinity-times-zero operation without an input NaN.
Finite FMA reports its dyadic rounding status and ternary value.
Complete invalid-status classification for fused multiply-add.
Finite operands take the singly rounded result's classification. Exceptional operands use the IEEE signaling-NaN, infinity-times-zero, and opposite-infinity rules. For the implementation-defined quiet-NaN case, this library raises invalid for infinity times zero even when the addend is a quiet NaN, while an input NaN suppresses the opposite-infinity condition.
Finite nonzero division reports its scaled-rational rounding status and ternary value.
Complete invalid-status classification for division.
The finite branch distinguishes zero-over-zero, exact zero, and nonzero rational rounding. Exceptional operands use the signaling-NaN and infinity-over-infinity rules.
Division raises divide-by-zero exactly for a finite nonzero numerator over finite zero.
Square-root cases #
Square root with status := true tests the sign bit first and decodes an input with a clear sign
bit once. The next theorems restate its outcome on NaNs, zeros, negative values, +∞, and
positive finite values. These cases cover every input.
When fmt.fracWidth + 1 < fmt.exponentBias, the square root of a nonzero decoded radicand never
lies below an underflow boundary. The least positive magnitude 2^minSubnormalExponent exceeds
the square of minNormal, 2^(2 * minNormalExponent), and every boundary is at most minNormal.
A NaN delivers the square-root value and raises invalid only when it is signaling.
A zero of either sign delivers the square-root value and raises nothing.
A negative value that is neither a NaN nor a zero, -∞ included, raises invalid.
+∞ delivers the square-root value and raises nothing.
On a positive finite input, the ternary value compares the squared delivery with the radicand, the
result is inexact exactly when that comparison is not .eq, and an inexact result underflows when
its encoding is zero or subnormal or its exact root lies below the underflow boundary.
Square root raises invalid exactly for an sNaN or a negative nonzero non-NaN input.
Dividing two finite zeros raises invalid.
Dividing a finite nonzero value by a finite zero raises divide-by-zero.
The square root of a negative nonzero non-NaN value raises invalid.
Square-root inexactness #
Square root raises inexact exactly when its ternary value is not .eq, on every input. The
flag is computed from that value on a positive finite input, and the other cases raise neither.
On a positive finite input, square root raises inexact exactly when the delivered value is not
the real square root of the input, in every rounding direction and for every descriptor.
The flag is computed as the ternary value's difference from .eq
(sqrt_inexact_eq_ternary_bne_eq), so on such an input the ternary value is .eq
exactly when the delivered value is the real square root.