irem 0x70
Takes the remainder of two ints on top of the stack; pushes the result.
- Opcode
0x70(112)- Family
- Arithmetic and bitwise
- Operands
- none
- Length
- 1 byte
- Operand stack
…, value1 (int), value2 (int) → …, result (int)- Can throw
ArithmeticException
What it does
a % b on two ints: pops b, then a, and pushes the result.
Dividing by zero throws ArithmeticException. Dividing the minimum value by -1 overflows quietly and gives the minimum value (and a remainder of 0).
How often javac uses it
In JDK 25.0.5's java.base module, irem appears 326 times in 119 of its 7,391 classes: 0.02% of all instructions, the 132nd most common of 194 opcodes in use. Some of the methods that use it: java.io.ObjectOutputStream$HandleTable.lookup, java.lang.CharacterName.<init>, java.lang.Integer.toString, java.lang.Math.floorMod.
Examples
From the sample classes, compiled by javac 25 with -g. Each Java line is shown above the bytecode it compiled to; irem is highlighted.
static int half(int n) in Asserts, compiled by javac 25static int whileLoop(int n) in Loops, compiled by javac 25Related instructions
lrem Takes the remainder of two longs on top of the stack; pushes the result.frem Takes the remainder of two floats on top of the stack; pushes the result.drem Takes the remainder of two doubles on top of the stack; pushes the result.
Specification: JVMS §6.5, irem (Java SE 25).