10.12.2012 Views

The Java Language Specification, Third Edition

The Java Language Specification, Third Edition

The Java Language Specification, Third Edition

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

15.18 Additive Operators EXPRESSIONS<br />

496<br />

• If the dividend is finite and the divisor is an infinity, the result equals the dividend.<br />

• If the dividend is a zero and the divisor is finite, the result equals the dividend.<br />

• In the remaining cases, where neither an infinity, nor a zero, nor NaN is<br />

involved, the floating-point remainder r from the division of a dividend n by a<br />

divisor d is defined by the mathematical relation r = n– ( d ⋅ q)<br />

where q is an<br />

integer that is negative only if n ⁄ d is negative and positive only if n ⁄<br />

d is<br />

positive, and whose magnitude is as large as possible without exceeding the<br />

magnitude of the true mathematical quotient of n and d.<br />

Evaluation of a floating-point remainder operator % never throws a run-time<br />

exception, even if the right-hand operand is zero. Overflow, underflow, or loss of<br />

precision cannot occur.<br />

Examples:<br />

5.0%3.0 produces 2.0<br />

5.0%(-3.0) produces 2.0<br />

(-5.0)%3.0 produces -2.0<br />

(-5.0)%(-3.0) produces -2.0<br />

15.18 Additive Operators<br />

<strong>The</strong> operators + and - are called the additive operators. <strong>The</strong>y have the same precedence<br />

and are syntactically left-associative (they group left-to-right).<br />

AdditiveExpression:<br />

MultiplicativeExpression<br />

AdditiveExpression + MultiplicativeExpression<br />

AdditiveExpression - MultiplicativeExpression<br />

If the type of either operand of a + operator is String, then the operation is<br />

string concatenation.<br />

Otherwise, the type of each of the operands of the + operator must be a type<br />

that is convertible (§5.1.8) to a primitive numeric type, or a compile-time error<br />

occurs.<br />

In every case, the type of each of the operands of the binary - operator must<br />

be a type that is convertible (§5.1.8) to a primitive numeric type, or a compiletime<br />

error occurs.<br />

DRAFT

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!