drem

Remainder double

Bytecode

Type Description
u1 drem opcode = 0x73 (115)

Stack ..., value1.word1, value1.word2, value2.word1, value2.word2 => ..., result.word1, result.word2

Description
Pops two double-precision numbers off the operand stack, divides by the top double, computes the remainder and pushes the double-precision result back onto the stack. This is like the C function fmod. The remainder is computed using the equation:

remainder = value2 - (intof( value2 / value1 ) * value1)

where intof () rounds towards the nearest integer, or towards the nearest even integer if the number is half way between two integers.

Both value1 and value2 must be of type double. The values are popped from the operand stack. The result is calculated and pushed onto the operand stack as a double.

The result of a drem instruction is not the same as that of the so-called remainder operation defined by IEEE 754. The IEEE 754 "remainder" operation computes the remainder from a rounding division, not a truncating division, and so its behavior is not analogous to that of the usual integer remainder operator. Instead, the Java Virtual Machine defines drem to behave in a manner analogous to that of the Java Virtual Machine integer remainder instructions (irem and lrem); this may be compared with the C library function fmod.

Despite the fact that division by zero may occur, evaluation of a drem instruction never throws a runtime exception. Overflow, underflow, or loss of precision cannot occur.

Notes

1. Divide by zero will result in NaN being pushed onto the stack as the result.

2. This operation is not the same as the IEEE-defined remainder operation, which uses slightly different rules for rounding. Use the Java library routine Math.IEEEremainder if you want the IEEE behavior.