6.1.3.4.6 MOD
Function
To find the modulo (return the remainder of division), divide the value of input IN1 by the value of input IN2, and query the remainder through output OUT
LD Graphics
Parameter description
| Interface variable | Declaration | Data type | Description |
|---|---|---|---|
| IN1 | Var_Input | ANY_INT | Dividend |
| IN2 | Var_Input | ANY_INT | Divisor |
| OUT | Var_Output | ANY_INT | Remainder |
Example
Through the MOD instruction, variable a is divided by variable b to obtain variable c, as shown in the following figure: three INT type variables are defined, and the MOD instruction is executed by compiling, downloading, and realizing that variable c is the remainder of variables a and b

warning
- The result of evaluating the MOD function shall be equivalent to the execution of the following ST statement:
IF(IN2 = 0) THEN
OUT := 0;
ELSE
OUT := IN1 - (IN1 / IN2) * IN2;
END_IF