Order of operations – Rockwell Automation 1771-DB BASIC MODULE User Manual
Page 113
Chapter
Expressions, Variables and Operators
9
9 -3
Eight types of operators may act on an expression:
G
arithmetic
G
functional
G
logical
G
logarithmic
G
relational
G
string
G
trigonometric
G
special function
An operator performs a defined operation on variables or constants.
Operators require either one (ex. SIN, COS, and ABS) or two operands
(ex. +, -,*, /).
You can write complex expressions using only a small number of
parentheses. An expression is scanned from left to right. Operators of the
higher precedence are performed before operators of lower precedence.
If the operators are of equal precedence they are performed as encountered
from left to right. The precedence of operators from highest to lowest:
1.
Operators that use parentheses ( )
2.
Exponentiation (**)
3.
Negation (-)
4.
Multiplication (*) and Division (/)
5.
Addition (+) and Subtraction (-)
6.
Relational Expressions (=, <>, >, >=, <, <=).
7.
Logical AND (.AND.)
8.
Logical OR (.OR.)
9.
Logical XOR (.XOR.)
To illustrate the order of operations, examine this equation:
4+3*2
In this equation you cannot perform addition until the multiplication
operation is complete because multiplication has a higher precedence.
Therefore, multiply (3*2) and then add 4.
4+3*2 = 10
Important: Use parentheses if you are in doubt about the order of
precedence or to enhance program readability.
Order of Operations