Operator precedence and order of evaluation
- Last Updated: July 8, 2021
- 1 minute read
- Corticon
- Version 7.2
- Documentation
Operator precedence is the order in which Corticon Studio evaluates multiple operators in an equation. Operator
precedence is described in the following table (also in the Rule
Language Guide.) This table specifies for example, that 2*3+4 evaluates to 10 and not 14 because the multiplication operator * has a higher precedence than the addition operator +. It is a good practice, however, to include clarifying parentheses even when
Corticon Studio does not require it. This
equation would be better expressed as (2*3)+4. Note the
addition of parentheses does not change the result. When expressed as 2*(3+4), however, the result is 14.
The precedence of operators affects the grouping and evaluation of
expressions. Expressions with higher-precedence operators are evaluated first. When several
operators have equal precedence, they are evaluated from left to right. The following table
summarizes Corticon's Rule Operator
precedence and their order of evaluation .
| Operator precedence | Operator | Operator Name | Example |
|---|---|---|---|
| 1 | ( ) | Parenthetic expression | (5.5 / 10) |
| 2 | - | Unary negative | -10 |
| not | Boolean test | not 10 | |
| 3 | * | Arithmetic: Multiplication | 5.5 * 10 |
| / | Arithmetic: Division | 5.5 / 10 | |
| ** | Arithmetic: Exponentiation (Powers and Roots) |
5 ** 2 25 ** 0.5 125 ** (1.0/3.0) |
|
| 4 | + | Arithmetic: Addition | 5.5 + 10 |
| - | Arithmetic: Subtraction | 10.0 – 5.5 | |
| 5 | < | Relational: Less Than | 5.5 < 10 |
| <= | Relational: Less Than Or Equal To | 5.5 <= 5.5 | |
| > | Relational: Greater Than | 10 > 5.5 | |
| >= | Relational: Greater Than Or Equal To | 10 >= 10 | |
| = | Relational: Equal | 5.5=5.5 | |
| <> | Relational: Not Equal | 5.5 <> 10 | |
| 6 | (expression and expression) | Logical: AND | (ent1.dec1 > 5.5 and ent1.dec1 < 10) |
| (expression or expression) | Logical: OR | (ent1.dec1 > 5.5 or ent1.dec1 < 10) |
Note: Even though expressions within
parentheses that are separated by logical AND/OR operators are valid, the component
expressions are not evaluated individually when testing for completeness, and might cause
unintended side effects during rule execution. The best practice within a Corticon Rulesheet is to represent AND conditions
as separate condition rows and OR conditions as separate rules -- doing so allows you to
get the full benefit of Corticon’s logical
analysis.
Note: It is recommended that you place
arithmetic exponentiation expressions in parentheses.