Java Reference
In-Depth Information
• The sum of two nonzero finite values of the same magnitude and opposite sign is
positive zero.
• In the remaining cases, where neither an infinity, nor a zero, nor NaN is involved,
and the operands have the same sign or have different magnitudes, the exact math-
ematical sum is computed. A floating-point value set is then chosen:
♦ If the addition expression is FP-strict (§ 15.4 ):
If the type of the addition expression is float , then the float value set must be
chosen.
If the type of the addition expression is double , then the double value set must
be chosen.
♦ If the addition expression is not FP-strict:
If the type of the addition 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 addition 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 sum.
If the magnitude of the sum is too large to represent, we say the operation over-
flows; the result is then an infinity of appropriate sign.
Otherwise, the sum is rounded to the nearest value in the chosen value set using
IEEE 754 round-to-nearest mode. The Java programming language requires sup-
port of gradual underflow as defined by IEEE 754 (§ 4.2.4 ).
The binary - operator performs subtraction when applied to two operands of numeric type,
producing the difference of its operands; the left-hand operand is the minuend and the right-
hand operand is the subtrahend .
For both integer and floating-point subtraction, it is always the case that a-b produces the
same result as a+(-b) .
Note that, for integer values, subtraction from zero is the same as negation. However, for
floating-point operands, subtraction from zero is not the same as negation, because if x is
+0.0 , then 0.0-x is +0.0 , but -x is -0.0 .
Despite the fact that overflow, underflow, or loss of information may occur, evaluation of a
numeric additive operator never throws a run-time exception.
Search WWH ::




Custom Search