# Java arithmetic instruction

De Software testing

## Concepts

- Java arithmetic instructions compute a result that is typically a function of two values on the operand stack, pushing the result back on the operand stack. <bib>lindholm-yellin:1999</bib>

## Facts

- There are two main kinds of Java arithmetic instructions: those operating on integer values and those operating on floating-point values. <bib>lindholm-yellin:1999</bib>

- There is no direct support for integer arithmetic on values of the byte, short, char, or boolean type; those operations are handled by instructions operating on type int. <bib>lindholm-yellin:1999</bib>

- Integer and floating-point instructions differ in their behavior on overflow and divide-by-zero. <bib>lindholm-yellin:1999</bib>

- The Java virtual machine does not indicate overflow during Java arithmetic instructions, but integer divide instructions (idiv and ldiv) and integer remainder instructions (irem and lrem), which throw an ArithmeticException if the divisor is zero. <bib>lindholm-yellin:1999</bib>

- Java virtual machine operates Java arithmetic instructions on floating-point numbers as specified in IEEE 754, requiring denormalized floating-point numbers, gradual underflow, and using the rounding mode known as round to nearest mode for floats and round towards zero when converting a floating-point value to an integer. <bib>lindholm-yellin:1999</bib>

- The arithmetic instructions are as follows:
- Add: iadd, ladd, fadd, dadd.
- Subtract: isub, lsub, fsub, dsub.
- Multiply: imul, lmul, fmul, dmul.
- Divide: idiv, ldiv, fdiv, ddiv.
- Remainder: irem, lrem, frem, drem.
- Negate: ineg, lneg, fneg, dneg.
- Shift: ishl, ishr, iushr, lshl, lshr, lushr.
- Bitwise OR: ior, lor.
- Bitwise AND: iand, land.
- Bitwise exclusive OR: ixor, lxor.
- Local variable increment: iinc.
- Comparison: dcmpg, dcmpl, fcmpg, fcmpl, lcmp. <bib>lindholm-yellin:1999</bib>