5 mixed mode (integers and reals) arithmetic – Rockwell Automation 57C610 Enhanced Basic Language, AutoMax User Manual

Page 39

Advertising
background image

5Ć7

The following are relational expressions:

A% > B%

((A%+3)/16) < > 32

(((A%/25) +13)+B%) >= SPEED%

(A% < > B%) OR (GAIN => 3.58867) OR (FAULTS% = 0)

(MESSAGE$ = SYSTEM DOWN")

(SPEED > OLD_SPEED + 23.8876/GAIN)

Since the result of a relational expression is a true or false value

(boolean result), several relational subĆexpressions may be

combined by using the boolean operators AND, OR, and XOR.
The following are statements using relational expressions:

10 IF (A% > B%) THEN 200
10 IF (SPEED < 32.887) AND (SECTION 5_on@) THEN

GOSUB 12000

10 IF SYSTEM STOPPED@ OR FAULTS@ OR (ROLL_

WIDTH% <23) THEN 240

5.5

Mixed Mode (Integers and Reals)

Arithmetic

In performing mixed mode arithmetic (expressions in which integers

and reals are intermixed), BASIC must always convert the integer

value to a real or decimal number internally to be able to operate on

the two quantities.
The integer must be converted to a real to maintain the maximum

amount of precision possible. (Converting the real to integer and

doing all integer arithmetic obviously is not feasible because all the

fractional parts would be lost; A=2.37764+4 should result in

6.37764 not 6.) This integerĆtoĆreal conversion happens only,

however, at the point where the integer value or subĆexpression

value is combined with a real value in an operation.
When BASIC evaluates an expression. it follows certain rules which

determine the order of evaluation in the expression. When using

mode arithmetic, use caution to assure the desired results.
If there are integer parts to the expression, BASIC will use integer

arithmetic until it encounters a real value and then convert the

integer partial result to real. For example, the following expression is

evaluated exactly as seen, left to right (because there are not

parentheses and all the operators are of the same precedence or

importance):

REAL3 = B% * C% * D% * REAL1 * REAL2

The above statement is evaluated as follows:
1. B% * C% will be calculated in integer arithmetic.
2. The intermediate value of (B% * C%) is then multiplied by D%

using integer arithmetic because both quantities are still

integers.

3. The intermediate value of [(B% * C%) * D%] is now multiplied by

REAL1, but since one of the values is real and one is integer, the

intermediate value of [(B% * C%) * D%] must be converted to a

real value before the multiplication by REAL1.

Advertising
This manual is related to the following products: