Operators in ST
Operators execute operations and provide functionality, such as addition. The operators combine the operands to form expressions.
Possible operators
No. |
Description of operation: symbol |
Examples |
Precedence |
1 |
parentheses: (expression) |
A + (B / C) (A + B) / C A / (B + C) |
12 (highest) |
2 |
call of function or call of a method, if there is a return value: identifier (parameter list) |
ABS(A) ADD(X,Y) |
11 |
3 |
dereference ^ Details: see under "Declaration of reference variables (incl. assignments to them)" |
R^ |
10 |
4 |
negation: – |
–A |
9 |
5 |
unary plus: + |
+B |
9 |
6 |
complement: NOT |
NOT C |
9 |
7 |
exponentiation: ** |
A ** B B ** B |
8 |
8 |
multiply: * |
A * B |
7 |
9 |
divide: / |
A / B A / B / D |
7 |
10 |
modulo: MOD |
A MOD B |
7 |
11 |
add: + |
A + B A + B + C |
6 |
12 |
subtract: – |
A – B A – B – C |
6 |
13 |
comparison: <, >, <=, >= |
A < B |
5 |
14 |
equality: = |
A = B A = B & B = C |
4 |
15 |
inequality: <> |
A <> B |
4 |
16a |
Boolean AND: & |
A & B A & B & C |
3 |
16b |
Boolean AND: AND |
A AND B |
3 |
17 |
Boolean exclusive OR: XOR |
A XOR B |
2 |
18 |
Boolean OR: OR |
A OR B |
1 (lowest) |
Notes:
Operators can be →overloaded.
Only comparison operators (=, <>, <, >, <=, >=) can be applied to the datatypes STRING and CHAR.
Only the equality operator = and the inequality operator <> can be applied to declared variables based on an →interface and NULL.
Comparing variables based on an interface or of such a variable with NULLinterface_variable_1 = interface_variable_2
interface_variable_1 = NULL
NULL = interface_variable_2
Operators return the same results as the according IEC-blocks provided that they work with the same data.
Example: Expression x+y for the addition has a behavior identical to this call of the ADD block: ADD(x,y)On error (e.g. in case of a division by 0), the value 0 is returned but the output ENO of the embracing →POU is not set to value FALSE (or an equivalent).
Mind the correct combination of the →literals/→variables for multiplication, division, addition and subtraction, if the operation is done for literals/variables of data type TIME. Other combinations will be highlighted as faulty.
operation: symbol
data type for operand and result
example
behavior identical to this block
multiply: *
1st operand: data type TIME
all following operands: data type belonging to →generic data type ANY_NUM
result: data type TIME
T#1m40s * 2 * 5
MUL_TIME block, with:
1st operand = IN1, all following operands are handled as IN2 is handled, result = return valuedivide: /
1st operand: data type TIME
2nd operand: data type belonging to ANY_NUM
result: data type TIME
T#1m40s / 2
DIV_TIME block, with:
1st operand = IN1, 2nd operand = IN2, result = return value The operator / calculates using the accuracy as entered for the 2nd operand. That means: If the 2nd operand is a REAL value, logi.CAD 3 is using a REAL value for the internal calculation . Compare: DIV_TIME is using LREAL for the internal calculation .add: +
1st operand: data type TIME
all following operands: data type TIME
result: data type TIME
T#3s + T#4s + T#1s
ADD_TIME block, with:
1st operand = IN1, all following operands are handled as IN2 is handled, result = return valuesubtract: -
1st operand: data type TIME
2nd operand: data type TIMEresult: data type TIME
T#4s - T#3s
SUB_TIME block, with:
1st operand = IN1, 2nd operand = IN2, result = return value