Formula operators
Operators are used to perform mathematical, comparative, and logical calculations on values in field control expressions.
Syntax
<first_value> <operator> <second_value>
The ()
math operator and !
logical operator use a different notation than other operators. See the tables for descriptions and examples of their usage.
Order of operations
Expressions that contain more than one operator are evaluated in a defined sequence called the order of operations. For example, the expression 2 + 10 / 5
returns 4
, because the division operation 10 / 5
is evaluated first, then the addition operation is evaluated.
Order of operations in expressions
Order | Operation | Operators |
---|---|---|
1 | Grouping | () |
2 | Exponent | ^ |
3 | Division and multiplication | /, div, %, mod, * |
4 | Addition and subtraction | +, - |
5 | Logical NOT | !, NOT |
6 | Comparison | <, <=, >, >= |
7 | Equality | =, ==, !=, <> |
8 | Logical AND | &&, AND |
9 | Logical OR | ||, OR |
Math operators
Math operators are symbols that you use to perform arithmetic calculations on integer and number values. Math operators return an integer or number value.
Math operators for use in expressions
Operator | Description | Example | Result |
---|---|---|---|
+ | Adds the second number to the first number. | 5 + 2 | 7 |
- | Subtracts the second number from the first number. | 5 - 2 | 3 |
* | Multiplies the first number by the second number. | 5.0 * 2 | 10.0 |
/ | Divides the first number by the second number. | 5.0 / 2 | 2.5 |
^ | Raises the first number to the power of the second number. | 5 ^ 2 | 25.0 |
() | Specifies that expressions within the brackets are evaluated first. Expressions outside the brackets are then evaluated using standard operator precedence. | 5.0 * (5 - 2) | 15.0 |
%, mod | Evaluates the modulo of two numbers. Divides the first number by the second number, then returns the remainder as the result. | 5 % 2 | 1 |
div | Performs integer division on two numbers. Divides the first number by the second number, then discards the remainder to return a whole number as the result. This is useful when you want to perform integer division on non-integer numbers. | 5.0 div 2.0 | 2.0 |
Comparison operators
Comparison operators are symbols that you use to determine equality or difference between values. Comparison operations return a Boolean value.
Comparison operators for use in expressions
Operator | Description | Example | Result |
---|---|---|---|
=, == | Compares the first value to the second value to determine if they are equal. | 5 = 2 | FALSE |
!=, <> | Compares the first value to the second value to determine if they are not equal. | 5 != 2 | TRUE |
< | Compares two values to determine if the first value is less than the second value. | 5 < 2 | FALSE |
> | Compares two values to determine if the first value is greater than the second value. | 5 > 2 | TRUE |
<= | Compares two values to determine if the first value is less than or equal to the second value. | 5 <= 2 | FALSE |
>= | Compares two values to determine if the first value is greater than or equal to the second value. | 5 >= 2 | TRUE |
Logical operators
Logical operators are symbols that you use to perform logical operations on values. Logical operators return a Boolean value.
Logical operators for use in expressions
Operator | Description | Example | Result |
---|---|---|---|
&&, AND | Compares two expressions to determine if they are both true. | (5 > 2) && (5 == 2) | FALSE |
||, OR | Compares two expressions to determine if one or the other is true. | (5 > 2) || (5 == 2) | TRUE |
!, NOT | Inverts a Boolean value or the Boolean result of a comparison or logical operation. | !(5 > 2) | FALSE |