Arithmetic Operators

The following table lists arithmetic operators with their corresponding default operator precedence. Operators with a numerically lower ranking are evaluated before operators with a numerically higher ranking, operators with the same ranking are evaluated left-to-right.

Operator

Description

Precedence Ranking

+

Unary + (implicit value of the following operand).

1

-

Unary – (inverts the value of the following operand).

1

**

Exponentiates the preceding operand to the following operand.

2

*

Multiplies the operands (commutative).

3

/

Divides the preceding operand by the following operand.

3

+

Adds the operands (commutative).

4

-

Subtracts the following operand from the preceding operand.

4

Arithmetic operator semantics

The type of an expression is determined by the type of the target operand. Where necessary the right operand is cast to the appropriate type to satisfy the target operand.

Arithmetic operators can only be used with numeric operands.

When using the exponentiation operator, the left operand must be a positive number if the second operand is not an integer, Otherwise a runtime error will occur. For example, -3 ** 2 produces the correct result of 9, whereas -3 ** 2.5 causes a runtime error.