Attention

IronPLC can only run very simple programs. The steps described are accurate but many language features are not yet supported.

Arithmetic Operators

Arithmetic operators perform mathematical computations on numeric values.

IEC 61131-3

Section 3.3.1

Support

Supported

Syntax

Operator

Syntax

Description

+

a + b

Addition

-

a - b

Subtraction

*

a * b

Multiplication

/

a / b

Division (integer division for integer types)

MOD

a MOD b

Modulo (remainder after division)

**

a ** b

Exponentiation (power)

-

-a

Unary negation

Description

Arithmetic operators apply to integer types (SINT, INT, DINT, LINT, USINT, UINT, UDINT, ULINT) and floating-point types (REAL, LREAL). For integer division, the result is truncated toward zero. The MOD operator returns the remainder of integer division and is defined only for integer types.

The unary negation operator - has higher precedence than the binary arithmetic operators. Exponentiation ** has higher precedence than multiplication, division, and modulo.

Example

PROGRAM main
    VAR
        a : INT := 17;
        b : INT := 5;
        sum : INT;
        diff : INT;
        product : INT;
        quotient : INT;
        remainder : INT;
    END_VAR

    sum := a + b;          (* 22 *)
    diff := a - b;         (* 12 *)
    product := a * b;      (* 85 *)
    quotient := a / b;     (* 3 *)
    remainder := a MOD b;  (* 2 *)
END_PROGRAM

See Also