DIV¶
Returns the quotient of two inputs.
Signature¶
┌─────────┐
IN1 ─┤ │
│ DIV ├─ OUT
IN2 ─┤ │
└─────────┘
FUNCTION DIV : ANY_NUM
VAR_INPUT
IN1 : ANY_NUM;
IN2 : ANY_NUM;
END_VAR
END_FUNCTION
The return type matches the input type. DIV accepts SINT,
INT, DINT, LINT, USINT, UINT, UDINT, ULINT,
REAL, LREAL. Inputs of different numeric types widen to the
wider one, which is also the return type; see
Type Conversions. The time and date types are
covered by the overloads below.
Inputs
Name |
Type |
Description |
|---|---|---|
|
|
The dividend. |
|
|
The divisor. Must be non-zero. |
Outputs
Name |
Type |
Description |
|---|---|---|
Return value |
|
IN1 divided by IN2. Same type as the inputs. |
Description¶
Returns IN1 divided by IN2. DIV(a, b) is the functional form
of the / operator: a / b. Both forms are equivalent.
For integer types, division truncates toward zero. Division by zero causes a runtime fault.
Time and date overloads¶
DIV and the / operator are also defined on the following time
and date operands (IEC 61131-3 Table 30). Each combination is the typed
function in the last column and computes what it computes.
IN1 |
IN2 |
Return value |
Same as |
|---|---|---|---|
|
|
|
The duration comes first: t / 2 is DIV_TIME, but 2 / t is an error, and so is dividing one duration by another.
Each typed function has a long form over LTIME, LDATE,
LTIME_OF_DAY and LDATE_AND_TIME (DIV_LTIME),
which applies when either operand is of a long type.
Any other combination of types is an error (P4049).
Example¶
result := DIV(42, 6); (* result = 7 *)
result := 42 / 6; (* result = 7, operator form *)
result := 7 / 2; (* result = 3, truncates toward zero *)
See Also¶
References¶
IEC 61131-3 §2.5.1.5.3