12.4 Operators and their order of operation
Mathematical expressions used in TreeAge Pro necessarily contain operators (such as addition or multiplication signs). This section describes operators available in creating expressions.
Arithmetic operators
These operators perform arithmetic on the values that surround them. TreeAge Pro uses the traditional syntax for expressions, for example an expression that adds three and seven would be written 3 + 7.
Symbol | Example | Description |
---|---|---|
+ | x+ y | Addition. Returns the sum of x and y. |
- | x - y | Subtraction. Returns the difference between x and y. (Also used for negation, i.e., to denote negative numbers.) |
* | x * y | Multiplication. Returns the product of x and y. |
/ | x / y | Division. Returns the quotient of x and y. |
^ | x ^ y | Exponentiation. Returns x to the yth power. |
( ) | x * (y + z) | Grouping. Returns the product of x and the sum of y and z. |
Relational operators
These operators return a true or false value, depending on the veracity of the expression in which they appear. A true value is represented by a numeric 1, a false value receives a numeric value of 0. Relational operators are useful in many settings: in If() and Choose() functions, in expressions evaluated at logic nodes, and in a Markov termination condition.
Symbol | Example | Description |
---|---|---|
< | x < y | Less than. Returns true if x is less than y, and false if x is greater than or equal to y. |
<= | x < = y | Less than or equal to. Returns true if x is less than or equal to y, and false if x is greater than y. |
> | x > y | Greater than. Returns true if x is greater than y, and false if x is less than or equal to y. |
>= | x > = y | Greater than or equal to. Returns true if x is greater than or equal to y, and false if x is less than y. |
= | x = y | Equals. Returns true if x equals y, and false if x is not equal to y. |
< > | x < > y | Not equal to. Returns true if x is not equal to y, and false if x equals y. |
It is also possible, using the appropriate relational expression syntax, to test one value in terms of two others. There are a number of acceptable forms, with the two basic ones being:
-
y < x < z - Returns true if x is both (a) greater than y and (b) less than z.
-
y > x > z - Returns true if x is both (a) less than y and (b) greater than z.
Other valid forms of this syntax can be created by substituting ">=" for ">" or "<=" for "<" (for example, expressions of the form "y <= x < z" and "y >= x >= z" are valid). These are the only valid substitutions, though (for example, expressions of the form "y < x > z" are not valid). Failure to follow these rules when creating relational expressions of this kind will likely result in unintended calculation results.
Logical operators
Three logical operators are also available: logical AND, logical (inclusive) OR, and logical NOT.
AND is represented by the ampersand (&), OR by the vertical bar (|), and NOT by the exclamation mark (!). Like the relational operators (which return 1 if a comparison is true and 0 if not), these logical operators are zero-centric. That is, any operand that is non-zero is treated as true, and only a zero operand is treated as false. The returned value is 1 if the evaluation is true, and 0 if false.
Symbol | Example | Description |
---|---|---|
& | w<x & y<z | Logical AND. Returns true if w is less than x AND y is less than z. |
| | w<x | y<z | Logical OR. Returns true if either w is less than x OR y is less than z. |
! | !( w < x ) | Logical NOT. Returns true if w is not less than x. |
Operator precedence
In most situations, you will not need to know the details of which operators bind most tightly. However, when formulas do not appear to calculate correctly, you should check this section to see if precedence is a factor.
Operator precedence is how TreeAge Pro decides where you intended to put parentheses. Consider the following example:
A + B * C + D
A quick check of the precedence list below indicates that multiplication has higher precedence (binds more tightly) than addition. TreeAge Pro will therefore interpret your expression as:
A + (B * C) + D
This process is continued until all uncertain bindings are resolved.
The table below lists the operators available in TreeAge Pro in order of precedence. Operators with higher precedence will bind more tightly. Adjacent operators having the same precedence value will be applied from left to right.
Operator | Character | Precedence Value |
---|---|---|
Unary minus | - | 8 |
Logical NOT | ! | 8 |
Exponent | ^ | 7 |
Multiplication | * | 6 |
Division | / | 6 |
Addition | + | 5 |
Subtraction | - | 5 |
Comparators | <, <=, etc... | 4 |
Logical AND | & | 3 |
Logical OR | | | 2 |
Parentheses, Brackets | (), [] | 1 |
Functional argument separator | ; | 1 |
Notice that parentheses are at the bottom of the list. This simply means that the operators inside the parentheses will bind tightly to stay within the parentheses. They are your most useful tool for indicating your particular precedence requirements.