Rockwell Automation 57C610 Enhanced Basic Language, AutoMax User Manual
Page 40

5Ć8
4. The intermediate value of ([B% * C%) *D%] * REAL1), which is
in real format, is now multiplied by REAL2, also in real format.
The result is then a real value which is loaded into variable
REAL3.
Note: If the variable on the left side of the equal sign were an
integer, the resultant real value would be truncated first and then
loaded into the variable.
The mixing of integers and reals in the previous example does not
result in a problem because, although there are intermediate integer
values, multiplication operators do not intermediate integer values,
multiplication operators do not cause any loss of precision as the
operations are performed (4 * 5.334 is the same as 4.00 * 5.334).
Problems may, however, occur when mixed mode arithmetic
involves division. Consider the following example in which the
operation (A%/B%) must occur first because of the parentheses:
10 A%=17:B%=3:REAL=13.7889
20 REAL2=(A%/B%) * REAL
The partial result of the first expressions is 5 (17 : 3 = 5.66666; the
fractional part 0.66666 is ignored because it is integer division). The
5 is then multiplied by 13.7889, yielding 68.9445 (5 x 13.7889), not
78.1370 (5.66666 x 13.7889).
Once an intermediate result in a BASIC expression is evaluated as a
real, the rest of the expression will also be done as real arithmetic.
The above expression could be modified as follows to get the full
precision from the division:
10 A% = 17:B%=3:REAL = 13.7889
20 REAL2=(1.0*A%/B%) *REAL
Multiplying the 1.0 (which is a real number) by the variable A%
forces A% to be converted to real. The result of (1.0 * A%) is then a
real value. Since (1.0 * A%) is real, B% must be converted to real to
be used in the division.
The following is a comparison of the execution times for different
arithmetic modes doing the same expression. Notice that the third
example, combining integer and real values, is the most time
consuming because of the conversion required on the integer
before the addition can be performed. It is, therefore, faster to do
arithmetic in either all real or all integer. If possible:
REAL = REAL + REAL1
250
m
sec
INT% = INT% + INT1%
210
m
sec
REAL = REAL + INT%
362
m
sec