Arithmetic operators occur in arithmetic operations, i. e. in expressions that contain integers or reals. There are two kinds of operators: Binary and unary arithmetic operators. Binary operators are listed in table (12.2), unary operators are listed in table (12.3).
Operator | Operation |
+ | Addition |
- | Subtraction |
* | Multiplication |
** | Exponentiation |
/ | Division |
Div | Integer division |
Mod | Remainder |
With the exception of Div and Mod, which accept only integer expressions as operands, all operators accept real and integer expressions as operands.
Remark The exponentiation operator (**) is available for overloading (chapter 15, page 868), but is not defined on any of the standard Pascal types (floats and/or integers).
For binary operators, the result type will be integer if both operands are integer type expressions. If one of the operands is a real type expression, then the result is real.
As an exception, division (/) results always in real values.
For unary operators, the result type is always equal to the expression type. The division (/) and Mod operator will cause run-time errors if the second argument is zero.
The sign of the result of a Mod operator is the same as the sign of the left side operand of the Mod operator. In fact, the Mod operator is equivalent to the following operation:
But it executes faster than the right hand side expression.