The binary * operator performs multiplication, producing the product of its operands. Multiplication is a commutative operation if the operand expressions have no side effects. While integer multiplication is associative when the operands are all of the same type, floating-point multiplication is not associative.
If an integer multiplication overflows, then the result is the low-order bits of the mathematical product as represented in some sufficiently large two's-complement format. As a result, if overflow occurs, then the sign of the result may not be the same as the sign of the mathematical product of the two operand values.
The result of a floating-point multiplication is governed by the rules of IEEE 754 arithmetic:
* If either operand is NaN, the result is NaN.
* If the result is not NaN, the sign of the result is positive if both operands have the same sign, and negative if the operands have different signs.
* Multiplication of an infinity by a zero results in NaN.
* Multiplication of an infinity by a finite value results in a signed infinity. The sign is determined by the rule stated above.
* In the remaining cases, where neither an infinity nor NaN is involved, the exact mathematical product is computed. A floating-point value set is then chosen:
o If the multiplication expression is FP-strict (§15.4):
+ If the type of the multiplication expression is float, then the float value set must be chosen.
+ If the type of the multiplication expression is double, then the double value set must be chosen.
o If the multiplication expression is not FP-strict:
+ If the type of the multiplication expression is float, then either the float value set or the float-extended-exponent value set may be chosen, at the whim of the implementation.
+ If the type of the multiplication 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 product. If the magnitude of the product is too large to represent, we say the operation overflows; the result is then an infinity of appropriate sign. Otherwise, the product is rounded to the nearest value in the chosen value set using 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, or loss of information may occur, evaluation of a multiplication operator * never throws a run-time exception.