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. Both inputs must share the same type.

Inputs

Name

Type

Description

IN1

ANY_NUM

The dividend.

IN2

ANY_NUM

The divisor. Must be non-zero.

Outputs

Name

Type

Description

Return value

ANY_NUM

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.

Example

result := DIV(42, 6);   (* result = 7 *)
result := 42 / 6;       (* result = 7, operator form *)
result := 7 / 2;        (* result = 3, truncates toward zero *)

See Also

  • MUL — multiplication

  • MOD — modulo

  • SUB — subtraction

References