div
Returns the Euclidean quotient of dividing this integer by the other one.
This function uses Euclidean division: the remainder is always non-negative, regardless of the sign of this integer. Since other is guaranteed to be other than zero, this function never throws.
Calling from Kotlin
Here's an example of calling this function from Kotlin code:
val x: Integer = Integer.fromLong(-7)
val y: NonZeroInteger = NonZeroInteger.fromLong(2)
val quotient: Integer = x / y
val remainder: NonNegativeInteger = x % y
check(quotient == Integer.fromLong(-4))
check(remainder == NonNegativeInteger.fromLong(1))
check(x == quotient * y.toInteger() + remainder.toInteger())Content copied to clipboard
Calling from Java
Here's an example of calling this function from Java code:
final Integer x = Integer.fromLong(-7);
final NonZeroInteger y = NonZeroInteger.fromLong(2);
final Integer quotient = x.div(y);
final NonNegativeInteger remainder = x.rem(y);
final boolean check = quotient.equals(Integer.fromLong(-4))
&& remainder.equals(NonNegativeInteger.fromLong(1));
if (!check) throw new IllegalStateException("Check failed.");Content copied to clipboard
See also rem for returning the Euclidean remainder of this division.
Since
5.2.0