Loading...
Select Version
&pagelevel(5)&pagelevel
The modulo operation returns the integer remainder of a division operation; the operator is the reserved name MOD.
Rules:
The operator name MOD must be preceded and followed by a space; otherwise, this string is interpreted as part of a variable name.
- The result is calculated according to the following formula:
A MOD B = A - (A / B) * B
Example
Assignment | Result |
/Y = 9 MOD 4 | 1 |
/Z = -9 MOD 4 | -1 |
Table 1:
The variable Y is assigned the value 1, since the expression is calculated as follows:
9 MOD 4 = 9 - (9 / 4) * 4
First the parentheses are solved: The division operation 9 : 4 yields the number 2.25; consequently, the number 2 is inserted in the equation:
9 MOD 4 = 9 - 2 * 4
According to the rules of arithmetic, this yields 9 - 8, i.e.:
9 MOD 4 = 1
Consequently, the value -1 is yielded and assigned to variable Z.
-9 MOD 4 = -9 - (-9 / 4) * 4 = -9 - (-2) * 4 = -9 - (-8) = -1