MOD¶
Returns the remainder after integer division.
Signature¶
┌─────────┐
IN1 ─┤ │
│ MOD ├─ OUT
IN2 ─┤ │
└─────────┘
FUNCTION MOD : ANY_INT
VAR_INPUT
IN1 : ANY_INT;
IN2 : ANY_INT;
END_VAR
END_FUNCTION
The return type matches the input type. MOD accepts SINT,
INT, DINT, LINT, USINT, UINT, UDINT, ULINT.
Both inputs must share the same type.
Inputs
Name |
Type |
Description |
|---|---|---|
|
|
The dividend. |
|
|
The divisor. Must be non-zero. |
Outputs
Name |
Type |
Description |
|---|---|---|
Return value |
|
The remainder of IN1 divided by IN2. Same type as the inputs; sign matches IN1. |
Description¶
Returns the remainder of IN1 divided by IN2. MOD(a, b) is the
functional form of the MOD operator: a MOD b. Both forms are
equivalent.
The result has the same sign as IN1. IEC 61131-3 defines the MOD
function only for integer types. Division by zero causes a runtime fault.
Example¶
result := MOD(7, 3); (* result = 1 *)
result := 7 MOD 3; (* result = 1, operator form *)
result := -7 MOD 3; (* result = -1 *)
See Also¶
References¶
IEC 61131-3 §2.5.1.5.3