Remainder int
Bytecode
Type | Description |
u1 | irem opcode = 0x70 (112) |
Stack ..., value1, value2 => ..., result
Description
Pops two ints off the operand stack, divides value2 by value1
(i.e. value2 / value1), computes the remainder and pushes the int remainder back onto the
stack. The remainder is (value2 - ((value1 / value2) * value2)). This is used by the %
operator in Java.
Both value1 and value2 must be of type int
. The values are
popped from the operand stack. The int
result is value1 - (value1
/ value2) * value2. The result is pushed onto the operand stack.
The result of the irem instruction is such that (a/b)*b
+
(a%b)
is equal to a
. This identity holds even in
the special case that the dividend is the negative int
of largest possible
magnitude for its type and the divisor is -1
(the remainder is 0
).
It follows from this rule that the result of the remainder operation can be negative only
if the dividend is negative and can be positive only if the dividend is positive.
Moreover, the magnitude of the result is always less than the magnitude of the divisor.
ArithmeticException - the divisor (value1) is zero.