Integral-rounding contracts #
The unbounded dyadic-to-integer kernel is related to the usual nearest-even, floor, ceiling, and truncation semantics. The floating-point wrapper then records exactly when fractional bits were discarded and exposes the exceptional branches.
For IEEE encodings with fmt.fracWidth ≤ fmt.maxNormalExponent, the selected integer is exactly
representable. This condition holds for the IEEE interchange formats. On finite inputs,
roundToIntegral then denotes the floor, ceiling, truncation, or nearest-even integer selected by
the rounding direction, and roundToIntegralExactWithStatus reports no overflow.
Exact zero rounds to integer zero in every direction.
Nearest-even integer rounding has its usual mathematical meaning, independently of the stored dyadic exponent or magnitude.
Rounding toward positive infinity computes the mathematical ceiling.
Rounding toward negative infinity computes the mathematical floor.
Rounding toward zero truncates the exact dyadic: nonnegative values use floor and negative values use ceiling.
A dyadic with a nonnegative exponent is already an integer.
Dyadic zero is integral independently of its stored sign and exponent.
An exact dyadic is integral precisely when no negative binary exponent leaves a fractional bit.
For exponent -(shift + 1), this says that 2^(shift + 1) divides the significand. A
nonnegative exponent is always integral.
roundToIntegral is exactly the value component of its status-bearing operation.
On finite input, roundToIntegralExactWithStatus rounds the exact dyadic to an unbounded integer,
then encodes that integer in the selected direction. The status records discarded fractional bits
and the encoder's overflow classification.
On finite input, roundToIntegralExactWithStatus raises inexact exactly when a negative binary
exponent leaves at least one fractional bit.
roundToIntegralExactWithStatus preserves either infinity and returns clear status.
roundToIntegralExactWithStatus quiets a NaN and raises invalid exactly when it was signaling.
Representability of the rounded integer #
Every rounding direction lands at or above the floor of the exact value.
Every rounding direction lands at or below the ceiling of the exact value.
If the significand is below 2^(fracWidth + 1) and the binary exponent is negative, the rounded
integer has magnitude at most 2^fracWidth.
An integer placed at exponent zero denotes itself.
On a finite input of an IEEE format whose exponent range reaches the precision, the result
represents the selected integer exactly and reports no overflow. Fractional input can still set
inexact.
Every IEEE interchange format satisfies fmt.fracWidth ≤ fmt.maxNormalExponent.
Integral rounding of a finite IEEE value never overflows when
fmt.fracWidth ≤ fmt.maxNormalExponent.
Integral rounding of a finite IEEE value is finite when the exponent range reaches the precision.
The real value of a finite integral rounding is the integer selected by roundDyadicToInt.
The result of integral rounding is an integer.
Rounding toward negative infinity computes the floor of the real value.
Rounding toward positive infinity computes the ceiling of the real value.
Rounding toward zero truncates the real value: floor when nonnegative, ceiling otherwise.
Rounding to nearest computes the nearest integer with ties to even, nearestEven from the Flocq
theory. Mathlib's round resolves ties toward positive infinity.