Instruction Manual
User Variables and Arithmetic • Arithmetic 129
Publication 1398-PM601A-EN-P — October 2000
TUTORIAL
Arithmetic
Four function arithmetic, addition (+), subtraction (-), multiplication (*), and division (/) is supported by
IQ Basic. The syntax for arithmetic is:
Precedence and Order of Evaluation
The following table summarizes the rules for precedence for all operators. Operators on the same line
have the same precedence; rows are in order of decreasing precedence. For example, * and / have the
same precedence, and have higher precedence than + and -.
Examples:
G1 = 3 + 4 * 2;G1 set equal to 11
G1 = (3 + 4) * 2;G1 set equal to 14
G1 = 3 + 4 * 2 + 4;G1 set equal to 15
Boolean Operators
The following Boolean operators are supported: AND, NAND, OR, NOR, XOR and NOT. The oper-
ands that are used with these operators include F flags, B flags, system flags and Inputs. The result can
be an F flag, B flag, system flag (except read-only flag) or output.
AND
F3 = F1 AND F2;F3 is ON if F1 and F2 are ON; otherwise, F3 is OFF
F1 F2 F1 AND F2
OFF OFF OFF
OFF ON OFF
ON OFF OFF
ON ON ON
Syntax result = operand operator operand [operator operand] …[operator operand]
result The result may be a nonvolatile variable Gn, a volatile
variable Vn, or certain system variables
operand The operand may be a nonvolatile variable Gn, a vola-
tile variable Vn, a system variable, or a constant
operator +, -, *, /
Operators
( ), @, UTOC1, UTOC2, CTOU1, CTOU2
* , /
+ , -
NOT, AND, OR, XOR, NAND and NOR
=