Exact rational rounding #
Division produces an exact rational rather than a dyadic. These routines round
(num / den) * 2^exponent directly, using integer quotient rounding and descriptor-derived normal,
subnormal, and overflow thresholds.
The leading exponent is computed before scaling, and a quotient below half the least subnormal is recognized from that exponent alone, so a format with a very wide exponent range does not materialize an enormous shifted numerator or denominator. Conventional IEEE descriptors use the proof-facing thresholds where convenient; custom biases and finite encodings follow the general path with the same one-rounding contract.
Exact rationals for division #
Round exact rational (num/den) * 2^exponent in a conventional IEEE descriptor.
The explicit isIEEE proof ensures that the layout-derived bias and exponent bounds agree with
the descriptor. Use roundRatScaled for a custom bias or a finite encoding; it selects the
appropriate rounder from the complete descriptor.
This is the division analogue of roundDyadic: the overflow, subnormal, and normal cases are the
same, and the mantissa is obtained by roundQuotientEven instead of the integer
roundShiftRightEven.
The normal-path mantissa scale is fracWidth - ⌊log₂(num/den)⌋: the external exponent cancels, so
wide-exponent formats do not materialize an enormous shifted numerator or denominator. A quotient
below half the least subnormal returns signed zero before any shift. A zero denominator is not a
rational value and returns the format's invalid-operation result.
Instances For
Round exact rational (num / den) * 2^exponent according to the complete format descriptor.
A quotient below half the least subnormal returns the format's zero from the leading exponent alone, without materializing the subnormal alignment shift. In the remaining paths, the shift is controlled by the numerator and denominator sizes and the destination precision, rather than the full exponent range.
Instances For
Round exact rational (num / den) * 2^exponent to Model fmt using nearest-even.
Instances For
Round exact rational num/den to Model fmt with nearest-even rounding.
Instances For
A zero denominator is rejected by scaled rational rounding.
A zero numerator rounds to the format's zero when the denominator is nonzero.
A zero denominator is rejected with the destination format's invalid-operation result.
A zero rational rounds to the format's zero when the denominator is nonzero.