IEEE remainder contracts #
IEEE remainder subtracts the nearest integer multiple of the divisor, with ties going to an even quotient. Reducing an aligned numerator modulo twice the divisor preserves both the remainder and the quotient parity needed to resolve a tie.
The finite kernel has this exact rational semantics. For finite inputs and a nonzero divisor in an IEEE encoding, the resulting dyadic is representable, so its final encoding loses no precision. Separate equations specify the value and status for zero divisors and infinities.
Nearest-even quotient arithmetic #
Exact finite remainder #
The optimized finite remainder kernel has the exact unbounded nearest-even quotient semantics.
When the dividend exponent is larger, modular exponentiation recovers the aligned numerator's quotient parity and remainder without constructing it. In the other direction, a sufficiently large exponent gap guarantees that the nearest quotient is zero, allowing an early return. Both paths agree with the unbounded aligned calculation below.
Zero has zero IEEE remainder against every nonzero finite divisor.
remainder is exactly the value component of its status-bearing operation.
Status-bearing exceptional branches #
For two finite operands with a nonzero divisor, the runtime encodes the selected dyadic remainder and returns clear status. A zero result uses the dividend's sign, subject to the format's zero policy.
A finite zero divisor makes IEEE remainder invalid.
A finite dividend is unchanged when the divisor is infinite.
An infinite dividend and finite divisor make IEEE remainder invalid.
Two infinite operands make IEEE remainder invalid.
Exactness of the encoded remainder #
The exact remainder is either the dividend itself or a dyadic at the exponent of one operand whose
significand is no larger than that operand's. These bounds establish representability in
remainderWithStatus_exact.
With a nonzero divisor, the remainder of two finite operands is exactly representable in an IEEE encoding. The final rounding preserves the exact dyadic's real value and produces a finite result, justifying the clear status on this branch.