SUB

Returns the difference of two inputs.

Signature

     ┌─────────┐
IN1 ─┤         │
     │   SUB   ├─ OUT
IN2 ─┤         │
     └─────────┘
FUNCTION SUB : ANY_NUM
  VAR_INPUT
    IN1 : ANY_NUM;
    IN2 : ANY_NUM;
  END_VAR
END_FUNCTION

The return type matches the input type. SUB 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 minuend.

IN2

ANY_NUM

The subtrahend.

Outputs

Name

Type

Description

Return value

ANY_NUM

IN1 minus IN2. Same type as the inputs.

Description

Returns IN1 minus IN2. SUB(a, b) is the functional form of the - operator: a - b. Both forms are equivalent.

For integer types, underflow behavior wraps around (modular arithmetic).

Example

result := SUB(30, 10);   (* result = 20 *)
result := 30 - 10;       (* result = 20, operator form *)

See Also

  • ADD — addition

  • MUL — multiplication

  • DIV — division

References