Exact dyadic rounding #
This is the executable one-rounding boundary for exact binary values. It classifies an exact dyadic against descriptor-derived overflow, normal, and subnormal regions, retains only the target significand bits, and applies nearest-even to the discarded part.
Conventional IEEE descriptors may reuse Lean's logical float model as a proof-facing route.
roundDyadicGeneral handles custom bias and every supported exceptional-value encoding directly.
The public selector keeps those implementations under one descriptor-level contract.
Round an exact dyadic through Lean's conventional IEEE logical model.
This is the proof-facing specification for formats with ordinary IEEE bias and exceptional-value
encoding. roundDyadic below selects it only when fmt.isIEEE.
Instances For
Right shifts preserve a zero mantissa with clear round and sticky bits.
Rounding in Lean's IEEE model preserves signed zero for every model format.
Rounding an exact zero through Lean's logical model packs the corresponding signed zero.
Default overflow result: infinity, NaN, or saturation according to the encoding.
Instances For
Conventional IEEE native overflow is the usual signed infinity.
Overflow result for a signed magnitude under a known rounding direction.
IEEE 754-2019 Section 7.4 rounds an overflowing magnitude to the format's overflow value when
the direction carries the magnitude upward and to the largest finite value when it carries the
magnitude downward. roundMagnitudeUp records that direction after the sign has been taken into
account: toward zero never rounds up, toward positive infinity rounds a positive magnitude up, and
toward negative infinity rounds a negative magnitude up. Nearest modes always round up. The
directed and policy rounders share this definition so that a finite-with-NaN encoding saturates
in the truncating direction under both engines.
Instances For
Pack a rounded subnormal significand.
The caller supplies the zero result because some directed algorithms know that a nonzero exact input must round to the least subnormal, while rational rounding uses the format's zero policy. Keeping the common boundary logic here prevents those algorithms from drifting apart.
Instances For
Pack a rounded normal significand, including carry into the exponent and descriptor-specific overflow words.
This helper accepts an already rounded significand. Callers remain responsible for proving that their rounding decision and supplied overflow result match the requested policy.
Instances For
Round an exact dyadic according to the complete format descriptor.
Only the retained significand and the discarded-bit rounding decision are materialized. The
implementation supports custom exponent bias and every FloatFormat.Encoding; it does not pass
through Lean's conventional IEEE model.
Instances For
Round an exact dyadic to Model fmt using round-to-nearest, ties-to-even.
Conventional IEEE formats retain the established logical-model specification and its checked native implementation. Other static formats use the descriptor-aware integer algorithm directly.
Instances For
Exact addition at the binary-format API boundary.
The implementation is shared with posit arithmetic and exact reductions through
Numerics.Dyadic.add; binary operations keep this name so their specifications read naturally.
No rounding occurs until the result is passed to roundDyadic.