Reference Manual

PMAC 2 Software Reference
PMAC Mathematical Features 361
If the divisor is equal to 0, the result will saturate at +/-2
47
(+/-2
23
for an integer
division in a compiled PLC). No error will be reported, and the program will not stop.
It is the programmer’s responsibility to check for possible division-by-zero errors.
Example
Command Result
P1=10*2/3
6.666666667
P1=10*(2/3)
6.666666667
M1=10*2/3
7
M1=10*(2/3)
7
L1=10*2/3
7
L1=10*(2/3)
10
L1 and M1 are integer variables; P1 is a floating-point variable
%
Function
Modulo (remainder)
Remarks
The % sign causes the calculation of the remainder due to the division of the numerical
value preceding it by the numerical value following it. Unless the division is executed
in a compiled PLC on a line with only L-variables and integers, the division operation
is always a floating-point calculation (even if integer values are used). The quotient is
computed as a floating-point value, then truncated to the next lowest (i.e., toward -)
integer so the remainder can be computed.
If the divisor “n” is a positive value, the modulo result is in the range {0 Result < n}.
If the divisor “n” is a negative value, the modulo result is in the range {–n Result <
n}.
Multiplication, division, modulo (remainder), and bit-by-bit “and” operations have
higher priority than addition, subtraction, bit-by-bit “or”, and bit-by-bit “exclusive-or”
operations. Operations of the same priority are implemented from left to right.
If the divisor is equal to 0, the division will saturate and the modulo result will be 0.
No error will be reported, and the program will not stop. It is the programmer’s
responsibility to check for possible division-by-zero errors.
Example
Operation Result
11%4
3
-11%4
1
11%-4
3
-11%-4
-3
3%2.5
0.5
-3%2.5
2
3%-2.5
-2
-3%-2.5
2