Expression Evaluator

Function

Calculates the result of an expression with integers, decimals, numeric variables, string variables (only for string comparisons), arithmetic and Boolean operators and a set of functions.

Properties

Properties

Description

Expression

Expression to be calculated.

Note

if the expression does not follow the correct syntax, the converter will not perform the calculation.

Mode

  • Read: read (link from source to parent)

  • Write: write (link from parent to source)

  • Read/write: read and write (link from parent to source and vice versa)

Source

One or more variables, identified by a placeholder with an index number, with the following format {index}. The index number is progressive, must be an integer greater than zero ({0}).

The placeholders can appear in any order in the expression.

Valid literal values

  • Boolean: true and false.

  • Integers

  • Decimals. The decimal separator must be a point.

  • Hexadecimal numbers with prefix “0x” (e.g. 0xff)

  • Text, delimited by double quotation marks (e.g. string)

    Note

    double quotation marks repeated twice ("") are interpreted as an escape sequence.

Valid Operators

  • Arithmetical: +, `` -`` , *, `` /`` , % and unary operator -

  • Bitwise: &, | , ^,``~``

  • Shift: <<, >>

  • Logics: &&, ||, !

  • Unary casting of (<data_type>) type

  • Comparison <, <=, >, >=, ==, !=

    Note

    all the comparison operators are applicable both to numeric data, and to DateTime and Duration data.

    Note

    the operators: == and != are also applicable to String and LocalizedText data types.

Datatype Conventions

  • Literal integers are Int32.

  • Decimal literals are Double.

  • Numerical values are considered to be Int32.

  • The following literals: true and false are interpreted as Boolean.

  • The / operator always returns a Double value.

  • The % operator generates an exception when there is division by modulo zero.

  • The % operator accepts Float and Double operands.

  • All the functions return a Double value except for the sign function, which returns an Int32 value.

  • The unary casting operator accepts the following datatypes:

    • bool, Boolean

    • sbyte, SByte

    • short, Int16

    • int, Int32

    • long, Int64

    • byte, Byte

    • ushort, UInt16

    • uint, UInt32

    • ulong, UInt64

    • float, Single

    • double, Double

Parentheses

The expression can contain an unlimited number of parentheses, correctly opened and closed.

Available Functions

These mathematical functions are available:

Function

Calculated value

Example

max

Maximum of two values

max ({0}, {1})

min

Minimum of two values

min ({0}, {1})

avg

Average of given values

avg ({0}, {1})

abs

Absolute value

abs ({0})

trunc

Integer part of a decimal number

trunc ({0})

ceil

Approximated value by excess

ceil (({0} + {1})/2)

floor

Approximated value by defect

floor (({0} + {1})/2)

round

Approximation to the nearest integer

round (({0} + {1})/2)

sqrt

Square root

sqrt ({1})

sign

0 if the argument value is greater than zero

1 if the argument value is less than zero

sign ({1})

Output

The resulting value of the expression.

Logical representation

The following image illustrates an example of a logical conversion in the advanced dynamic link editor.

See also

Related concepts

Converters

Related procedures

Using the Advanced Dynamic Link Editor