Arithmetic Operators
The arithmetic operators compute a numeric value from two operands.
+addition-subtraction*multiplication/division%remainder
Process
At runtime:
- the left operand is evaluated;
- the right operand is evaluated; and
- the operator is applied to both values, and its result is the expression's value.
For integer types, / truncates towards zero and % yields the remainder of truncating division, which has the sign of the dividend. Integer arithmetic wraps on overflow: signed integer types wrap in two's complement, and unsigned integer types wrap modulo 2^N, where N is the type's width. For floating-point types, all operators follow IEEE 754 semantics.
Integer division by zero, or integer remainder by zero, produces a runtime error; see the runtime error model.
Assertions
- Both operands are numeric types within the same family: signed integer, unsigned integer, or floating-point.
- The remainder operator
%requires integer operands. - The operands have a common type, and the result has that type.
- When the surrounding context requires a type within the operator's applicable family, each operand's expected type is that required type.
Syntax
additive_operator = plus | minus ;
multiplicative_operator = star | solidus | percent ;