Operators

The following operators may be used in an expression:

Arithmetic operators

Operator Effect for numbers Effect for strings Effect for Boolean
+ Addition Concatenation Logical OR
- Subtraction Invalid operation Logical OR inverted
* Multiplication Invalid operation Logical AND
/ Division Invalid operation Logical AND inverted
% Modulo1 Invalid operation *
^ Power *1 *

1The % (modulo or modulus) operator calculates the remainder after division. For example, 12 % 10 is 2. At school you might have said it as “12 divided by 10 is 1, with remainder 2". Similarly, 20 % 10 is zero because there is no remainder.

Comparison operators

Sign Operator
> Greater than
< Less than
>= Greater or equal
<= Less or equal
= Equal
!= Not equal

If the types of the left and right expressions are different, the right expression will be converted to the type of left expression before making the comparison. Comparison operations produce a Boolean result.

The following range checks are supported:

(expr) (comparison operator1) (expr) (comparison operator2) (expr)

Where both comparison operators are less than (or equal), or greater than (or equal), but not both.

Less than or equal

a<b<c
for example: 2<x<3 returns true if x is greater than 2 but less than 3

a<=b<c
for example: 2<=x<3 returns true if x is greater than or equal to 2 but less than 3

a<b<=c

for example: 2<x<=3 returns true if x is greater than 2 but less than or equal to 3

a<=b<=c
for example: 2<=x<=3 returns true if x is greater than or equal to 2 and less than or equal to 3

Greater than or equal

a>b>c
for example: 2>x>3 returns true if x is less than 2 but greater than 3

a>=b>c
for example: 2>=x>3 returns true if x is less than or equal to 2 but greater than 3

a>b>=c
for example: 2>x>=3 returns true if x is less than 2 but greater than or equal to 3

a>=b>=c
for example: 2>=x>=3 returns true if x is less than or equal to 2 and greater than or equal to 3

The operator has the same precedence as normal comparison operators, so:

2<=2+1<4

evaluates to True.

Logic operators

Sign Operator
& Logical AND
| Logical OR
! Logical NOT

In the following example the Logical OR (pipe) operator is used in a field expression to define a filter. If a record contains either 1, 2 or 3 in its BLOCK field, then the record passes the filter:

=[BLOCK] = "1" | [BLOCK] = "2" | [BLOCK] = "3"

The same expression can be written more succinctly using the IN function:

=IN([BLOCK], "1", "2", "3")

Conditional operators

The expression parser has a conditional operator 'if'. It has the following syntax:

if <predicate> then
    <expression_true>
elseif|elif <predicate> then
    <expression_true>
else
    <expression_false>
endif|fi

The elsif|elif part of the operator can be repeated, or be skipped completely. The logic is to evaluate predicates until the one that evaluates to TRUE is found, and then evaluate the corresponding <expression_true>. If no predicate evaluates to TRUE, then <expression_false> is evaluated and this becomes the result.

You can use the 'if' operator in the following way:

MCAF + if RECOVERY > 0.5 then MCAF * 2 else 0 fi

In other words, if the RECOVERY is greater than 0.5, then add MCAF * 2 to MCAF, otherwise add 0 (nothing).

Type conversion operators

The result type of an expression is determined by the type of the first operand. However, this is not always convenient since something like:

=[RL] + "m"

will give an unexpected result.

A unary operator “#" that can be used to convert an operand, clause, or expression to a string is handy in these situations. So:

=#[RL] + "m"

gives the correct result.

A few examples are shown in the following table:

=3 + 4 produces the number 7, whereas:
=#(3 + 4) produces the text “7", and:
=#3 + 4 produces the text “34", which is simply the concatenation of 3 and 4.

Unless otherwise stated, the type of the right expression will be converted to the type of the left expression before executing the operation.

i.e. "5.05" will be the (concatenated) result of “5.0" + 5, and 10 will be the (arithmetic) result of 5.0 + “5".

Literal constants take precedence when determining the context type. For example:

=2 + "3"

evaluates to 5, but if A is a variable with value 2,

=A + “3”

evaluates to 23.