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; 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 ordinary cast is the nearest-even specialization of the directed cast.
Status-bearing conversion preserves the value selected by the directed cast.
Casting a finite value to its own format is an exact identity, including signed zero.
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 remains 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; 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.
Every rounding mode uses the same bit-exact compatible finite widening.
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.
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.