UD70
Issue code: 70nu2
4-16
DPL programming
4.8 Optimizing
programs
In order for programs to run effectively, the following are recommended.
Integer variables
Use integer variables where possible, rather than floating-point variables.
The processing of a floating-point variable is 20 times slower than for an
integer variable. (See
INT
instruction in Chapter 7 Reference.)
Fixed-point arithmetic
To represent decimal places, use fixed-point arithmetic. For example, if a
resolution of .001
.001 is required, let 11 be represented by 1000
1000. This allows
accuracy to be maintained throughout mathematical operations.
The output from an expression must then be corrected by a relevant
dividing factor.
Example
a% = 1500
//
“a% = 1.5”
b% = 2500
//
“b% = 2.5”
c% = a% * b%
//
c% = 3750000
// Divide by 1000 to adjust c%
c% = c% / 1000
//
“c% = 3750”
// To convert to the real value, we must divide by 1000 again
#1.21 = c% / 1000
//
“c% = 3.75”
Temporary integer variables
Minimize the number of times parameters are accessed. Instead of
accessing a parameter repeatedly, use temporary integer variables if a
parameter value is needed more than once. The access time for a
parameter is 50 times greater than that for a variable.
Example
IF #1.21 > 100 THEN
range% = 1
ELSEIF #1.21 > 200 THEN
range% = 2
ENDIF
This becomes:
temp% = #1.21
IF temp% > 100 THEN
range% = 1
ELSEIF temp% > 200 THEN
range% = 2
ENDIF
Summary of Contents for UD70
Page 6: ......
Page 14: ...UD70 Issue code 70nu2 2 6 Installation...
Page 42: ...UD70 Issue code 70nu2 4 20 DPL programming...
Page 98: ...UD70 Issue code 70nu2 7 22 Reference...