Java Reference
In-Depth Information
♦ If the division expression is FP-strict (§ 15.4 ) :
If the type of the division expression is float , then the float value set must be
chosen.
If the type of the division expression is double , then the double value set must
be chosen.
♦ If the division expression is not FP-strict:
If the type of the division expression is float , then either the float value set or
the float-extended-exponent value set may be chosen, at the whim of the im-
plementation.
If the type of the division expression is double , then either the double value
set or the double-extended-exponent value set may be chosen, at the whim
of the implementation.
Next, a value must be chosen from the chosen value set to represent the quotient.
If the magnitude of the quotient is too large to represent, we say the operation
overflows; the result is then an infinity of appropriate sign.
Otherwise, the quotient is rounded to the nearest value in the chosen value set us-
ing IEEE 754 round-to-nearest mode. The Java programming language requires
support of gradual underflow as defined by IEEE 754 (§ 4.2.4 ) .
Despite the fact that overflow, underflow, division by zero, or loss of information may oc-
cur, evaluation of a floating-point division operator / never throws a run-time exception.
15.17.3. Remainder Operator %
The binary % operator is said to yield the remainder of its operands from an implied divi-
sion; the left-hand operand is the dividend and the right-hand operand is the divisor .
In C and C++, the remainder operator accepts only integral operands, but in the Java pro-
gramming language, it also accepts floating-point operands.
The remainder operation for operands that are integers after binary numeric promotion
5.6.2 ) produces a result value such that (a/b)*b+(a%b) is equal to a .
This identity holds even in the special case that the dividend is the negative integer of
largest possible magnitude for its type and the divisor is -1 (the remainder is 0 ).
It follows from this rule that the result of the remainder operation can be negative only if
the dividend is negative, and can be positive only if the dividend is positive. Moreover, the
magnitude of the result is always less than the magnitude of the divisor.
Search WWH ::




Custom Search