Rounding-direction theorems for P3109 projection #
Format.roundFiniteToPrecision expresses an exact finite dyadic in units of the descriptor
quantum 2^Q, with Q = max(floor(log2 |X|), 1 - B) - P + 1, and then chooses between the two
integers bracketing the scaled magnitude. This module proves that the deterministic modes make
the choice the report prescribes:
towardZerotruncates: the result has the smaller magnitude and lies within one quantum;upanddownbracket the input from the requested side;nearestAwayandneareststay within half a quantum, and on an exact tie select the larger magnitude, respectively the candidate whose P3109 code is even;toOddstays within one quantum, and forP > 1it returns an odd significand whenever nonzero bits were discarded.
The bounds concern rational denotations before saturation and cover every descriptor width,
including P = 1. Projection.Selection and Projection.Rational.Selection prove the
stochastic selection formulas for every supplied random word.
Quantum exponent selected by P3109 precision rounding for a nonzero finite dyadic.
This is the Q of Section 4.7.4: the selected precision grid has spacing 2^Q before saturation.
Instances For
The quantum 2^Q as a positive rational.
Rational sign factor of a dyadic.
Instances For
Structural description of one precision-rounding step.
The input equals sign * (lower + rem / 2^d) * 2^Q with rem < 2^d, and the result significand
is lower or lower + 1, as roundAway decides.
Precision rounding keeps the selected quantum exponent whenever the result is nonzero.
The rounded result is an integer multiple of the quantum 2^Q.
Together with the direction theorems below this pins the result down to one of the two grid points bracketing the input.
Directed modes #
towardZero truncates: the result never exceeds the input in magnitude and is within one
quantum of it.
Every grid point no larger in magnitude than the input is no larger than the truncation.
up never rounds down and stays within one quantum above the input.
down never rounds up and stays within one quantum below the input.
Every grid point at or above the input is at or above the up result.
Every grid point at or below the input is at or below the down result.
Nearest modes #
nearestAway rounds to within half a quantum of the input.
On an exact tie, nearestAway selects the candidate of larger magnitude.
nearest rounds to within half a quantum of the input.
On an exact tie, nearest selects the candidate whose P3109 code is even.
The input is exactly halfway between lower * 2^Q and (lower + 1) * 2^Q in magnitude, and the
result has magnitude lower * 2^Q exactly when the lower code is even under the report's
CodeIsEven rule (including its P = 1 special case).
With more than one significand bit, a nearest tie yields an even significand.
Round to odd #
toOdd stays within one quantum of the input.
With more than one significand bit, toOdd returns an odd significand whenever rounding was
inexact.