ceilDiv

fun ceilDiv(x: Int, y: Int): Int

Returns the smallest (closest to negative infinity) int value that is greater than or equal to the algebraic quotient. There is one special case: if the dividend is Integer.MIN_VALUE and the divisor is -1, then integer overflow occurs and the result is equal to Integer.MIN_VALUE.

Normal integer division operates under the round to zero rounding mode (truncation). This operation instead acts under the round toward positive infinity (ceiling) rounding mode. The ceiling rounding mode gives different results from truncation when the exact quotient is not an integer and is positive.

  • If the signs of the arguments are different, the results of ceilDiv and the / operator are the same.

    For example, ceilDiv(-4, 3) == -1 and (-4 / 3) == -1.

  • If the signs of the arguments are the same, ceilDiv returns the smallest integer greater than or equal to the quotient while the / operator returns the largest integer less than or equal to the quotient. They differ if and only if the quotient is not an integer.

    For example, ceilDiv(4, 3) == 2, whereas (4 / 3) == 1.

Return

the smallest (closest to negative infinity) int value that is greater than or equal to the algebraic quotient.

Since

18

Parameters

x

the dividend

y

the divisor

See also

.ceil

Throws

if the divisor y is zero