Operators


Arithmetic operators

The following is the arithmetic operators defined in Macro Expert.

Operator Description Example
+ Adds two numbers. %=100 + 120%.
- Returns the difference between two numeric expressions. %=100 - v_b%.
* Multiplies two numbers. %=20 * v_b%.
/ Divides two numbers. %=20 / v_b%.
Mod
or \
Divides two numbers and returns only the remainder. %=v_b \ 10%.
int Divides two numbers and returns an integer result. %=25 int 10%.
pow Return the result of a number raised to a power (exponent). %=2 ^ 3%.

Comparison Operators

The following are the arithmetic operators defined in Macro Expert.

Operator Description Example
> Greater than %=v_a > 10%.
>= Greater than or equal to %=v_a >= 10%.
< Less than %=v_a < 10%.
<= Less than or equal to %=v_a <= 10%.
!= Not equal to %=v_a != 10%.
!== For string only, not exactly equal to %=v_a !=='Macro'%.
== Equal to %=v_a == 10%.
=== For string only, exactly equal to. %=v_b === "Hello" %.
LIKE Retrun TRUE if the value on the left matches the right pattern. A pattern can include regular characters and wildcard characters %=v_b Like "He*o" %.
LIKENC With no case sensitive, return TRUE if the value on the left matches the right pattern. A pattern can include regular characters and wildcard characters %=v_b Likenc "He*o" %.
CONTAINS
or CT
Return True if the value on the left contains the value on the right. %=v_b Contains "Hello" %.
CONTAINSNC
or CTNC
With no case sensitive, return True if the value on the left contains the value on the right. %=v_b ctnc "Hello" %.

Logical Operators

The following are the arithmetic operators defined in Macro Expert.

Operator Description Example
AND Performs a logical conjunction on two Boolean expressions. %=v_a and v_b%.
OR Performs a logical disjunction on two Boolean expressions. %=v_a or v_b%.
XOR Performs a logical exclusion on two Boolean expressions. %=v_a xor v_b%.
NOT Performs logical negation on a Boolean expression. %=not (v_a > v_b)%.

Bitwise Operators

The following are the bitwise operators defined in Macro Expert.

Operator Description Example
& Performs a logical bitwise AND on two integer expressions. %=v_a & v_b%.
| Performs a logical bitwise OR on two integer expressions. %=v_a | v_b%.
^ Performs a logical bitwise XOR on two integer expressions. %=v_a ^ v_b%.
~ Performs a logical bitwise NOT on an integer expressions. %= ~v_a%.

Operator Precedence

When expressions contain operators from more than one category, they are evaluated according to the following rules:

  • The arithmetic operators have the order of precedence described in Precedence Order, and all have greater precedence than the comparison, logical, and bitwise operators.

  • All comparison operators have equal precedence, and all have greater precedence than the logical and bitwise operators, but lower precedence than the arithmetic operators.

  • The logical and bitwise operators have the order of precedence described in the Precedence Order, and all have lower precedence than the arithmetic, comparison operators.

  • Operators with equal precedence are evaluated left to right in the order in which they appear in the expression.

Precedence Order

Operators are evaluated in the following order of precedence:

  1. Logical bitwise NOT (~) and logical conditional negation (NOT)
  2. Exponentiation (POW)
  3. Multiplication and division (*, /)
  4. Integer division (INT)
  5. Modulus arithmetic (MOD)
  6. Addition and subtraction (+, –)
  7. Comparison operators (>, >=, <, <=, LIKE, LIKENC, CONTAINS, CONTAINSNC)
  8. Equality and inequality (==, ===, !=, !==)
  9. Logical bitwise conjunction (&)
  10. Logical bitwise exclusive disjunction (^)
  11. Logical bitwise inclusive disjunction (|)
  12. Logical conditional conjunction (AND)
  13. Logical conditional exclusive disjunction (XOR)
  14. Logical conditional inclusive disjunction (OR)

Overriding Precedence

You can use parentheses to force some parts of an expression to be evaluated before others. The following example illustrates this.

%= (8 + 4 ) * 20%

%= 8 * ( ( 20 + 4 ) * 20 )+4%

Additional References