frem
Operation
Remainder float
Forms
frem = 114 (0x72)
Stack
..., value1, value2 ..., result
Description
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
.
The result of an frem instruction is governed by these rules:
- If either value is NaN, the result is NaN.
- If neither value is NaN, the sign of the result equals the sign of the dividend.
- If the dividend is an infinity, or the divisor is a zero, or both, the result is NaN.
- If the dividend is finite and the divisor is an infinity, the result equals the dividend.
- If the dividend is a zero and the divisor is finite, the result equals the dividend.
- In the remaining cases, where neither an infinity, nor a zero, nor NaN is involved, the floating-point remainder result from a dividend value1 and a divisor value2 is defined by the mathematical relation
, where q is an integer that is negative only if
is negative and positive only if
is positive, and whose magnitude is as large as possible without exceeding the magnitude of the true mathematical quotient of value1 and value2.
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
.