Expressions can use the following operators:
|^||Power of (e.g. c^2)|
|+%, -%||Increase by a percentage, Decrease by a
e.g 18 +% 5 = 18.9 and 18 -% 5 = 17.1
|*, /, %, >>, <<, &&, !!, ||, ^^||Multiplication, Division, Modulus, Shift Right, Shift Left, Bit wise AND, Bit wise NOT, Bit wise OR, Bit wise XOR (eXclusive OR)|
|+, -, &||Addition, Subtraction, String concatenation|
|>, <, >=, <=, <>, =, eq, ne, gr, ls, ge, le||Greater, Less than, Greater or equal, Less or equal, Not equal, Equal, String equal, String not equal, String greater, String less, String greater or equal, String less or equal|
|IN||Inclusion operator. For details see below|
The precedence of CalcIt operators is the one above with the first (high) at the top.
Plus (+) operator is used to add two numeric values or to concatenate alphanumeric values. At first the operator tries to convert the two values in numeric values. If this is not possible for any of the two then a string concatenation takes place. If the two values can be converted in numbers then a normal addition takes place. For string concatenation the & operator does a faster job.
The usual Comparison operators (
<, >=, <=, <>, =) can be used to compare numeric or alphanumeric
values. If the compared values can be converted in numbers then a numeric
comparison takes place. If any of the two cannot be converted to a number then a
lexicographical comparison takes place. Operators
ne, gr, ls, ge, le perform only string (lexicographical)
comparisons. If we need the maximum speed we can get
in a long running code then these operators will improve performance a lot.
Inclusion operator (IN) is used to check if a value is included in an array expression. Returns TRUE (1) if it is included or FALSE (0) if it is not. The implicit search operation is not case sensitive in case of alphanumeric data. We can use the keyword SORTED or NSORTED to signal operator IN to use a much faster search algorithm (binary search) if the data returned by the array expression are sorted properly. That means alphabetically with no case sensitivity for SORTED or numerically for NSORTED.
The syntax is:
where ValueToCheck is a value to check and ArrExpr an array expression. See examples below:
[1,200,400,500,800] //using inline
array sorted numerically
Where ar is an array variable and Included a simple variable that accepts the result (TRUE or FALSE) of the operation.
Commands that return sorted arrays (SORT, UNIQUE, SORTN) also signal IN to use the faster algorithm without the need of SORTED/NSORTED keywords. See also Array Expressions and Inline arrays.
This operator is used to assign a value to a simple variable or array position. E.g.
||Increments a variable by one. e.g.
||Decrements a variable by one. e.g.
Where NExpr is an expressions that returns numeric value and Expr is an expressions that returns numeric or alphanumeric value.
Special operators can be applied equally in simple variables, File variables, Buffer variables fields and Arrays elements.
AND and OR logical operators work with "short circuit Boolean evaluation". Consider the following:
a:=cont1 and cont2 and cont3 and cont4;
Instead of evaluating all the conditions to calculate the final result the evaluation stops in the point the final result is already decided. In the above example evaluation stops in the first condition that returns FALSE and the whole expression returns FALSE. The rest of conditions are not evaluated. Something similar happens when OR is in place of AND. The evaluation of the whole expression stops at the first condition that returns TRUE and the final result is of course TRUE.
NOTE: Bit wise operators
>>, <<, &&, ||, !!,
^^ expect 32 bit unsigned integers. Numbers out of the range of a
unsigned 32 bit integers will be truncated to 32 bits.