Expressions > Syntax rules

Operators

Operators allow you to make complex calculations with arithmetic operations within expressions. Operators use operands to act upon. Normally, operators are used in the following order:

Operand1 Operator Operand 2;

For example:

OUT1 := 5;

This example shows the use of the addition operator:

OUT1 := 5 + 5;

Normally, the value of the calculation is assigned to either an output, external reference, or temporary variable. The following operators are supported in DeltaV expressions:

+, -, *, /, AND, OR, NOT, XOR, MOD, !, =,<>, ~=, !=, <, >, <=, >=, **, :=, (,), x?y:z, ~, ^,&, %

Note

The equality operator (=) takes precedence over the AND and OR operators. However, it is important to write your expressions using parenthesis so that the result is as expected.

Table: Operator Description

Operator

Description

Notes

*

Multiply

The multiplication operator (*) causes its two operands to be multiplied.

/

Divide

The division operator (/) causes the first operand to be divided by the second. If the first operand is less than zero and the second operand is zero, the divide operator returns the value -3.402823466e+38. If the first operand is greater than or equal to zero and the second operand is zero, the divide operator returns the value +3.402823466e+38.

+

Add

The addition operator (+) causes its two operands to be added.

-

Subtract

The subtraction operator (-) causes the second operand to be subtracted from the first.

? :

Conditional

The conditional operator is a ternary operator (it takes three operands).

Result := Conditional-expression ? Expression : Expression The first operand is evaluated and all side effects are completed before continuing.

When the first operand evaluates to True (a nonzero value), the second operand is evaluated.

When the first operand evaluates to False (0), the third operand is evaluated.

For example, the expression alpha<beta ? delta : gamma; (where alpha and beta are simple operands) means that if alpha is less than beta, then evaluate delta; otherwise, evaluate gamma.

You many need to rearrange your operands to use the ?: operator. For example, to write the conditional statement:

IF IN1 < 90 THEN
    OUT1 := IN1;
ELSE
    OUT1 := 90;ENDIF;

using the ?: operator, the statement is as follows:

OUT1 :=(IN1<90) ? IN1 : 90
Note

Always simplify the second and third operands when using the ?: operator.

&

Bitwise AND

The AND (bit) operator compares each bit of its first operand to the corresponding bit of its second operand. If both bits are 1, the corresponding resultant bit is set to 1. Otherwise, the corresponding resultant bit is set to 0.

AND

Logical AND

The logical AND operator produces the value 1 if both operands are 1 (non-zero). If either operand is 0, the result is 0.

|

Bitwise OR

The inclusive OR (bit) operator compares each bit of its first operand to the corresponding bit of its second operand. If either bit is 1, the corresponding resultant bit is set to 1. Otherwise, the corresponding resultant bit is set to 0.

OR

Logical OR

The logical OR operator performs an inclusive OR operation on its operands. The result is 0 if both operands are 0. If either operand has a non-zero value, the result is 1.

~

Bitwise NOT

The bitwise complement (or bitwise NOT) operator produces the bitwise complement of its operand.

Note

This operator only works on signed values.

! or NOT

Logical NOT

The logical negation (logical NOT) operator sets the result to 0 if its operand is TRUE (non-zero). If its operand is False (0), the result is 1.

^

Bitwise Exclusive OR

The OR (bit) operator compares each bit of its first operand to the corresponding bit of its second operand. If one bit is 0 and the other bit is 1 (non-zero), the corresponding resultant bit is set to 1. Otherwise, the corresponding resultant bit is set to 0.

In other DeltaV applications (such as DeltaV Operate), this operator is defined differently. Refer to the application's definition when writing expressions in other application's editors.

XOR

Logical Exclusive OR

The logical exclusive OR operator compares the first operand to the second operand. If one operand is 0 and the other is 1 (non-zero), the result is 1. Otherwise, the result is 0.

MOD or %

Modulus operator

MOD is the remainder of simple integer division. For example, 13 / 5 (13 divided by 5) is 2 with a remainder of 3. Therefore, 13 MOD 5 is 3. When the division is inexact, the result is determined by the following rules:
  • When the right operand is zero, the result is zero.
  • When both operands are positive, the result is positive.
  • When either operand is negative and the result is inexact, the result is defined as follows:
    • In division where either operand is negative, the direction of truncation is toward zero.
  • When either operation is negative in division with the remainder operator, the result has the same sign as the dividend (the first operand in the expression). For example -13 MOD 5 is -3, but 13 MOD -5 is 3.

=

Equality test

The first operand is equal to second operand.

>

Greater than

The first operand is greater than the second operand.

<

Less than

The first operand is less than the second operand.

>=

Greater than or equal to

The first operand is greater than or equal to second operand

<=

Less than or equal to

The first operand is less than or equal to second operand.

!= or <> or ~=

Does not equal

The first operand is not equal to the second operand.

Note

The ~= operator only works on signed values.

**

Raise to power

(Exponent)

The power operator computes the first operand raised to the power of the second operand. If the first operand is negative and the second operand is not an integer, the result is zero.

In other DeltaV applications (such as DeltaV Operate), this operator is defined differently. Refer to the application's definition when writing expressions in other application's editors.

:=

Assignment to output

The simple-assignment operator assigns its right operand to its left operand.

Note

The expression evaluator is stack oriented and allows a maximum of 32 operands and operators. The use of parentheses to organize the expression minimizes the stack usage. The equations are evaluated using RPN (Reverse Polish Notation).

Table: Operator Precedence Rules

Precedence Order

Operation

Symbol

Order of Evaluation

1

Parenthesis

(Expression)

Nonassociative

2

Raise to power

**

Left

3

Logical NOT

Bitwise NOT

! or NOT

~

Left

4

Multiply

Divide

Modulus Operator

*

/

MOD or %

Left

5

Add

Subtract

Unary minus

+

-

-

Left

6

Equality test

Greater than

Less than

Greater than or equal to

Less than or equal to

Does not equal

=

>

<

>=

<=

!= or <> or ~=

Left

7

Bitwise AND

&

Left

8

Bitwise Exclusive OR

^

Left

9

Bitwise OR

|

Left

10

Logical AND

AND

Left

11

Logical Exclusive OR

XOR

Left

12

Logical OR

OR

Left

13

Conditional

?:

Right