Correctness of binary format casts #
A finite cast decodes the source exactly and applies one nearest-even rounding step in the destination format. The real-valued rounding bridge assumes conventional IEEE descriptors and a finite result, and it does not assign a real value to an infinity or NaN.
References #
- IEEE Standard for Floating-Point Arithmetic, IEEE 754-2019, Section 5.4.2. https://doi.org/10.1109/IEEESTD.2019.8766229
- S. Boldo and G. Melquiond, "Flocq: A Unified Library for Proving Floating-Point Algorithms in Coq," 2011. https://doi.org/10.1109/ARITH.2011.40
The directed cast kernel computes cast in every rounding direction.
The status cast kernel is cast with status := true.
A cast with status := true delivers the value of the cast in the same direction.
Casting a finite value to its own format is the identity, signed zero included.
NaN propagation #
Rebuilding a NaN from its sign and IEEE payload gives the quieted NaN.
This is the same-descriptor case of IEEE 754-2019 §6.2.3, so cast could use propagatedNaN on
every NaN. It keeps quietNaN on the same descriptor because that path avoids field packing.
A propagated NaN is a NaN in every destination that has a NaN encoding.
On a NaN source, cast in any rounding direction is propagatedNaN on the source sign and IEEE
payload, for equal and unequal descriptors alike (IEEE 754-2019 §6.2.3).
Casting a NaN into a destination with no NaN encoding raises invalid in every rounding mode.
Such a destination has no NaN to deliver, so cast returns positive zero and reports the lost
NaN through the invalid flag.
Exact widening preserves the sign bit.
Exact widening preserves the biased exponent field.
Exact widening shifts the stored fraction into the high end of the destination field.
A finite value stays finite under exact widening.
Exact same-exponent widening preserves the decoded real value.
For a nonzero finite value, widening left-shifts the integer significand by
dst.fracWidth - src.fracWidth and the destination scale loses the same number of powers of two,
so the represented real number is unchanged.
A destination with at least as many fraction bits and no larger minimum subnormal exponent has a finer dyadic grid. This grid has no upper exponent bound.
Representability is preserved by extension to a finer dyadic grid.
Equal biases and increased precision preserve the entire rounded-real grid.
Compatible finite widening preserves the complete field encoding, including signed zero, in every rounding mode.
Casting across compatible exponent semantics with at least as much precision is exact.
For conventional IEEE source and destination formats, executable casting refines one nearest-even rounding step in the destination's real-valued model.
Casting any finite binary descriptor to an IEEE destination performs one nearest-even real rounding, provided the delivered result is finite. The source may use a custom bias or a finite-only encoding.
Conventional IEEE casting into a finer dyadic grid is exact whenever the executable result is finite. This permits a wider exponent field and covers the usual exact standard-format widening conversions.
A finer destination grid preserves the real value of every finite source descriptor, including finite-only encodings. It needs a finite result because grid inclusion does not bound the destination's upper exponent range.