Understanding precedence of operators – Rockwell Automation 1771-DB Basic Module User Manual - Series A User Manual

Page 85

Advertising
background image

Operating Functions

Chapter 5

5–48

Although this method of angle reduction provides a simple and economical
means of generating the appropriate arguments for a Taylor series, there is
an accuracy problem associated with this technique. The accuracy problem
is noticed when the user argument is large (i.e. greater than 1000). This is
because significant digits, in the decimal (fraction) portion of reduced
argument are lost in the (user arg/PI – INT(user arg/PI)) expression. As a
general rule, keep the arguments for the trigonometric functions as small as
possible.

You can write complex expressions using only a small number of
parenthesis. To illustrate the precedence of operators examine the
following equation:

4+3*2 =?

In this equation multiplication has precedence over addition.

Therefore, multiply (3*2) and then add 4.

4+3*2 = 10

When an expression is scanned from left to right an operation is not
performed until an operator of lower or equal precedence is encountered.
In the example you cannot perform addition because multiplication has
higher precedence. Use parentheses if you are in doubt about the order of
precedence. The precedence of operators from highest to lowest in the
BASIC Module is:

1)

Operators that use parenthesis ()

2)

Exponentiation (**)

3)

Negation (–)

4)

Multiplication (*) and division (/)

5)

Addition (+) and subtraction (–)

6)

Relational expressions (=,

tu , u, u=, t, t=).

7)

Logical and (.AND.)

8)

Logical or (.OR.)

9)

Logical XOR (.XOR.)

5.5.2
Unary Operators
(continued)

5.5.3
Understanding Precedence
of Operators

Advertising