Operators

Operators are a compact way of specifying frequently used calculation operations like addition or multiplication. When multiple operators are used the order in which they are evaluated needs to be defined. The order can be explicitly specified by using parentheses. If there are no parentheses, the order is determined implicitly using the precedence of the operators. Higher precedence operators are evaluated first, followed by lower precedence. Within the same precedence group, operations are evaluated from left to right or from right to left depending on the operator.

Examples:

  • a + b + c = (a + b) + c
  • a + b * c = a + (b * c)
  • - - a = -(-a)
  • cond1? val1: cond2? val2: val3 = cond1? val1: (cond2? val2: val3)

The following table shows the precedence of operators. The operators on the first line have the highest precedence. Operators on the same line have the same precedence and the evaluation direction is specified as left-to-right or right-to-left.

Operators

Arguments

Evaluation

- ~ !

unary

Right-to-left

**

binary

Left-to-right

* / %

binary

Left-to-right

+ -

binary

Left-to-right

< > <= >= =

binary

Left-to-right

BIT_AND &

binary

Left-to-right

BIT_XOR ^

binary

Left-to-right

BIT_OR |

binary

Left-to-right

AND &&

binary

Left-to-right

XOR ^^

binary

Left-to-right

OR ||

binary

Left-to-right

?:

ternary

Right-to-left

,

binary

Left-to-right

For details of the operators, see the toolbox in the calculated signals editor.