Deterministic nearest-even shift rounding #
Power-of-two nearest-even rounding shared by binary floating-point, fixed-point, and other quantized representations. Guard, parity, and sticky bits decide rounding without constructing a halfway marker.
Remainder discarded by shifting a natural number right.
Writing the operation this way avoids constructing 2^shift. When shift exceeds the input's
bit length, the quotient is zero and the remainder is the original value.
Instances For
The bits discarded by a right shift are exactly the remainder modulo 2^shift.
Round value / 2^shift to the nearest natural number, breaking exact halfway cases toward even.
This is the power-of-two specialization of roundQuotientEven. It belongs in the common
quantization layer because binary floats, P3109 formats, and fixed-point kernels all discard low
binary digits in the same way. The guard bit decides whether rounding can increase the quotient.
The first shift retains the guard bit alongside the quotient. Only a set guard bit with an even
quotient requires checking whether shifting those retained bits back recovers the original value.
One low-byte extraction supplies both the guard bit and the quotient's parity.
Instances For
Shifting by no bits leaves the value unchanged.
Nearest-even rounding in guard-and-sticky form.
The quotient is incremented exactly when the guard bit is set and either a sticky bit is set or the quotient is odd.
Nearest-even shift rounding in quotient/remainder form.
Nearest-even shifting is nearest-even division by the corresponding power of two.
Nearest-even shift rounding is never below the floor quotient.
Nearest-even shift rounding is at most one above the floor quotient.
Rounding an exact multiple of two by one bit is exact.