15.17.2
Additive Operators (
+
and
) for Numeric Types
EXPRESSIONS
In the code, note the careful conditional generation of the singular
bottle
when appropriate rather than the plural
bottles
; note also how the string con
catenation operator was used to break the long constant string:
"You take one down and pass it around:"
into two pieces to avoid an inconveniently long line in the source code.
15.17.2 Additive Operators (
+
and
) for Numeric Types
The binary
+
operator performs addition when applied to two operands of numeric
type, producing the sum of the operands. The binary
operator performs subtrac
tion, producing the difference of two numeric operands.
Binary numeric promotion is performed on the operands ( 5.6.2). The type of
an additive expression on numeric operands is the promoted type of its operands.
If this promoted type is
int
or
long
, then integer arithmetic is performed; if this
promoted type is
float
or
double
, then floating point arithmetic is performed.
Addition is a commutative operation if the operand expressions have no side
effects. Integer addition is associative when the operands are all of the same type,
but floating point addition is not associative.
If an integer addition overflows, then the result is the low order bits of the
mathematical sum as represented in some sufficiently large two's complement
format. If overflow occurs, then the sign of the result is not the same as the sign of
the mathematical sum of the two operand values.
The result of a floating point addition is determined using the following rules
of IEEE arithmetic:
If either operand is NaN, the result is NaN.
The sum of two infinities of opposite sign is NaN.
The sum of two infinities of the same sign is the infinity of that sign.
The sum of an infinity and a finite value is equal to the infinite operand.
The sum of two zeros of opposite sign is positive zero.
The sum of two zeros of the same sign is the zero of that sign.
The sum of a zero and a nonzero finite value is equal to the nonzero operand.
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 sum is computed. If the magnitude of the sum is too large to represent, we
358
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Inexpensive Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Jsp Hosting
Cheap Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved