Language and Conventions Overview | Expressions
An arithmetic expression is the combination of constants, variables, and arithmetic operators. The following is a list of the arithmetic operators and their functions:
Operator |
Operation Performed |
+ |
Addition |
- |
Subtraction |
* |
Multiplication |
/ |
Division |
** |
Exponentiation |
= |
Set Equal To, Assign |
The hierarchy (order of evaluation) of these operators is shown below. The operators with the highest priority are at the top and the operators with the lowest priority are at the bottom. However, in cases where operators of equal priority appear in an expression, the system will evaluate the expression from left to right.
Operator |
Operation Performed |
** |
Exponentiation |
+ & - |
Unary Addition & Subtraction |
/ & * |
Division & Multiplication |
+ & - |
Binary Addition & Subtraction |
= |
Assignment |
The words unary and binary refer to the number of items effected by the operators + and -. Unary refers to an operation which is performed on one value only, such as a simple negation (A = -3). Binary refers to an operation which is performed on two values, such as the addition or subtraction of two numbers.
The order in which the operations in an expression are performed can be controlled by the use of parentheses. Expressions within parentheses will be evaluated before expressions without parentheses. In addition, if expressions in parentheses are nested within expressions in parentheses, the expression in the innermost set of parentheses is evaluated first. The use of parentheses in the evaluation of numerical expressions is shown below.
Expression |
Value |
4 + 2 * 5 - 12 / 3 |
10 |
( 4 + 2 ) * 5 - 12 / 3 |
26 |
4 + 2 * ( 5 - 12 / 3 ) |
6 |
4 + 2 * ( ( 5 - 12 ) / 3 ) |
-2 / 3 |