26. Returning the flooring/ceiling modulus
Having the dividend / divisor = quotient computation, we know that the floor operation applied to the (dividend, divisor) pair returns the largest integer that is less than or equal to the algebraic quotient. By the largest integer, we understand the integer closest to positive infinity. Starting with JDK 8, this operation can be obtained via Math.floorDiv()
and, starting with JDK 18, Math.floorDivExact()
.
On the other hand, the ceil operation applied to the (dividend, divisor) pair returns the smallest integer that is greater than or equal to the algebraic quotient. By the smallest integer, we understand the integer closest to negative infinity. Starting with JDK 18, this operation can be obtained via Math.ceilDiv()
and Math.ceilDivExact()
.
More details are available in Problem 22.
Now, based on the floor and ceil operations, we can define the following floor/ceil modulus relationships:
Floor_Modulus = dividend -
(floorDiv...