
In formulas you can use the numerical and logical operators that are described on this page. The order of evaluation of the operators is the order that is most usual in programming languages. To force a different order, you use parentheses.
The operators with the highest precedence are negation () and exponentation (^):
6 → 6
2^6 → 64
Sequences of negation and exponentiation are evaluated from right to left:
2^6 → 0.015625
(1+1)^6 → 64
4^3^2 → 4^9 → 262144
Note that changing the spacing does not change the meaning:
4^3 ^ 2 → 262144
To change the order of evaluation, you have to use parentheses:
(4 ^ 3) ^ 2 → 4096
The following construction is not allowed because of an ambiguity between a negative number and negation of a positive number:
2^6 → ?
Instead, you use any of the following:
(2)^6 → 64
(2^6) → 64
(2)^6 → 64
The operators with the next highest precedence are multiplication (*) and division (/). They are evaluated from left to right:
1/4*5 → 1.25 (from left to right)
1 / 4*5 → 1.25 (spacing does not help)
1 / (4*5) → 0.05 (use parentheses to change the order)
3 * 2 ^ 4 → 48 (exponentiation before multiplication)
3*2 ^ 4 → 48 (this spacing does not matter and is misleading)
(3 * 2) ^ 4 → 1296 (use parentheses to change the order)
Integer division operators (div and mod) have the same precedence as * and /, and are likewise evaluated from left to right:
54 div 5 → 10 (division rounded down)
54 mod 5 → 4 (the remainder)
54.3 div 5.1 → 10 (works for real numbers as well)
54.3 mod 5.1 → 3.3 (the remainder)
54 div 5 → 11 (division rounded down; negation before division)
54 mod 5 → 1 (the remainder)
(54 div 5) → 10 (use parentheses to change the order)
(54 mod 5) → 4
3 * 18 div 5 → 10 (from left to right)
3 * (18 div 5) → 9
3 * 18 mod 5 → 4
3 * (18 mod 5) → 9
54 div 5 * 3 → 30 (from left to right)
54 div (5 * 3) → 3
54 mod 5 * 3 → 12
54 mod (5 * 3) → 9
The operators with the next highest precedence are addition (+) and subtraction (), evaluated from left to right:
3  8 + 7 → 2 (from left to right)
3  (8 + 7) → 12 (use parentheses to change the order)
3 + 8 * 7 → 59 (multiplication before addition)
(3 + 8) * 7 → 77 (use parentheses to change the order)
3 +  (2 ^ 4) → 13 (exponentiation, negation, addition)
3 + 5 / 2 + 3 → 8.5
(3 + 5) / (2 + 3) → 1.6
The operators with the next highest precedence are the comparison operators (=, <>, <, >, <=, >=
). These operators always yield 0 (false) or 1 (true):
5 + 6 = 10 → 0 (equal)
5 + 6 = 11 → 1
5 + 6 <> 10 → 1 (unequal)
5 + 6 <> 11 → 0
5 + 6 < 10 → 0 (less than)
5 + 6 < 11 → 0
5 + 6 > 10 → 1 (greater than)
5 + 6 > 11 → 0
5 + 6 <= 10 → 0 (less than or equal)
5 + 6 <= 11 → 1
5 + 6 >= 10 → 1 (greater or equal)
5 + 6 >= 11 → 1
The comparison operators are mainly used in if, while, and until conditions.
The operators of lowest precedence are the logical operators (not, and, and or), of which not has the highest precedence and or the lowest:
not 5 + 6 = 10 → 1
x > 5 and x < 10 (is x between 5 and 10?)
not x <= 5 and not x >= 10 (means the same as the previous line)
not (x <= 5 or x >= 10) (means the same as the previous line, unless x is undefined)
text$ = "hallo" + "dag"
soundFileName$ = "hallo.aifc"
textgridFileName$ = soundFileName$  ".aifc" + ".TextGrid"
© ppgb, September 13, 2017