Smart Card Solution
User Manual
- R502 Manual
JavaCard API Samples
- Algorithm
Java Card Specification
Knowledge Sharing
Smart Card Solution
User Manual
JavaCard API Samples
Java Card Specification
Knowledge Sharing
Divide int
Format
idiv
Forms
idiv = 72 (0x48)
Stack
…, value1.word1, value1.word2, value2.word1, value2.word2 → …, result.word1, result.word2
Description
Both value1 and value2 must be of type int. The values are popped from the operand stack. The int result is the value of the Java expression value1 / value2. The result is pushed onto the operand stack.
An int division rounds towards 0; that is, the quotient produced for int values in n/d is an int value q whose magnitude is as large as possible while satisfying | d · q | = | d | and n and d have the same sign, but q is negative when | n | >= | d | and n and d have opposite signs.
There is one special case that does not satisfy this rule: if the dividend is the negative integer of the largest possible magnitude for the int type, and the divisor is -1, then overflow occurs, and the result is equal to the dividend. Despite the overflow, no exception is thrown in this case.
Runtime Exception
If the value of the divisor in an int division is 0, idiv throws an ArithmeticException.
Notes
If a virtual machine does not support the int data type, the idiv instruction will not be available.