Remainder float
Bytecode
Type | Description |
u1 | frem opcode = 0x72 (114) |
Stack ..., value1, value2 =>..., result
Pops two single-precision numbers off the operand stack, divides by the top float, computes the remainder and pushes the single-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 float
. The values are
popped from the operand stack. The result is calculated and pushed onto the operand
stack as a float
.
The result of an frem instruction is not the same that of the as 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 frem 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 an frem instruction never throws a runtime exception. Overflow, underflow, or loss of precision cannot occur.
Notes
The IEEE 754 remainder operation may be computed by the Java library routine Math.IEEEremainder
.