Investment Studio > Expressions > Operators
Operators act on values (operands) and return new values. Most operators take two operands (dyadic operators). Some act on a single operand (unary operators).
Some operators support array operands. All can be applied to arrays using the MOP function.
There are five broad categories of operators: arithmetic, comparison, logical, string and reference. Operators from all categories can be mixed freely in any expression (automatic type conversion rules apply).
If an expression contains more than one operator, the order of evaluation is determined by operator precedence rules.
| Operator | Meaning | ||||
| + (plus sign) |
Addition. Dyadic form: A + B The operands A and B are converted to floats, then added. A and B may be arrays, in which case corresponding array elements are added (standard matrix addition). Array operands must have identical dimensions. See also functions SUM and MSUM. Unary form: +A The operand A is converted to a float. This can be used as to force type conversion. The operand A may be an array, in which case each array element is converted to a float. |
||||
| - (minus sign) |
Subtraction. Dyadic form: A - B The operands A and B are converted to floats, then subtracted (B from A). A and B may be arrays, in which case corresponding array elements are subtracted (standard matrix subtraction). Array operands must have identical dimensions. See also function MSUB. Unary form: -A The operand A is converted to a float, then its sign is changed. The operand may be an array, in which case each array element is converted to a float and its sign is changed. |
||||
| * (asterisk) |
Multiplication. Form: A * B The operands A and B are converted to floats, then multiplied. A or B or both may be arrays:
|
||||
| / (forward slash) |
Division. Form: A / B The operands A and B are converted to floats, then A is divided by B. A may be an array, in which case each array element is converted to a float and individually divided by B (standard scalar matrix division). Division by an array is not defined. The closest equivalent in matrix arithmetic would be matrix inversion (see function MINVERSE) of the "divisor", followed by multiplication from the left by the "dividend". |
||||
| div | Integer division. Form: A div B The operands A and B are converted to integers, then A is divided by B and the remainder is discarded. In other words, A div B returns the value of A / B rounded in the direction of zero to the nearest integer. Built-in identifiers are not case sensitive. Hence "div", "Div" and "DIV" are all equally valid spellings. See also function QUOTIENT. |
||||
| mod | Modulus. Form: A mod B The operands A and B are converted to integers, then A is divided by B and the remainder is returned. In other words, A mod B = A (A div B) * B. Built-in identifiers are not case sensitive. Hence "mod", "Mod" and "MOD" are all equally valid spellings. See also function MOD. |
||||
| % (percent sign) |
Percent. Form: A% (unary, left-associative). The single operand A is converted to float, then multiplied by 0.01. |
||||
| ^ (caret) |
Exponentiation. Form: A^B The operands A and B are converted to floats, then the base A is raised to the exponent B. For B fractional or larger than 2^31 - 1, the base A must be equal to or larger than 0. See also function POWER. |
| Operator | Meaning |
| = (equal sign) |
Equality. Dyadic form: A = B The operands A and B are promoted to the lowest common data type (integer, float or string, from low to high), then their values are compared. The result is TRUE if the values are identical, FALSE otherwise. String comparison is case-insensitive, i.e. "S" = "s" is TRUE. For case sensitive string comparison, use EXACT. A and B may be arrays, in which case corresponding array elements are compared; they must all be equal for the two arrays to be equal. Arrays with different dimensions are always considered unequal. Unary form: =A This is not really an operator at all. A leading equal sign simply denotes the start of an expression. Depending on the context, it may be implied. |
| > (greater than sign) |
Greater than. Form: A > B The operands A and B are promoted to the lowest common data type (integer, float or string, from low to high), then their values are compared. The result is TRUE if the value of A is larger than the value of B, FALSE otherwise. Strings are compared according to the ordering of the extended ASCII character set but without regard to case, i.e. "T" > "s" is TRUE. |
| < (less than sign) |
Less than. Form: A < B The operands A and B are promoted to the lowest common data type (integer, float or string, from low to high), then their values are compared. The result is TRUE if the value of A is smaller than the value of B, FALSE otherwise. Strings are compared according to the ordering of the extended ASCII character set but without regard to case, i.e. "s" < "T" is TRUE. |
| >= (greater than or equal sign) |
Greater than or equal to. Form: A >= B The operands A and B are promoted to the lowest common data type (integer, float or string, from low to high), then their values are compared. The result is TRUE if the value of A is greater than or equal to the value of B, FALSE otherwise. Strings are compared according to the ordering of the extended ASCII character set but without regard to case, i.e. "T" >= "s" is TRUE. |
| <= (less than or equal sign) |
Less than or equal to. Form: A <= B The operands A and B are promoted to the lowest common data type (integer, float or string, from low to high), then their values are compared. The result is TRUE if the value of A is less than or equal to the value of B, FALSE otherwise. Strings are compared according to the ordering of the extended ASCII character set but without regard to case, i.e. "s" <= "T" is TRUE. |
| <> (inequality sign) |
Not equal to. Form: A <> B The operands A and B are promoted to the lowest common data type (integer, float or string, from low to high), then their values are compared. The result is TRUE if the value of A differs from the value of B, FALSE otherwise. Strings are compared according to the ordering of the extended ASCII character set but without regard to case, i.e. "s" <> "S" is FALSE. A and B may be arrays, in which case corresponding array elements are compared; it's enough for one element pair to differ for the two arrays to be unequal. Arrays with different dimensions are always considered unequal. |
| Operator | Meaning | |
| and | Logical AND. Form: A and B Both operands are converted to booleans, then TRUE is returned is both A and B are TRUE. If either A or B is FALSE, FALSE is returned. Built-in identifiers are not case sensitive. Hence "AND", "And", "and" are all equally valid spellings. |
|
| or | Logical OR. Form: A or B Both operands are converted to booleans, then TRUE is returned if either A or B is TRUE. If both A and B are FALSE, FALSE is returned. Built-in identifiers are not case sensitive. Hence "OR", "Or", "or" are all equally valid spellings. Since it's enough for
one of the operands to be TRUE for OR to be TRUE, either
operand may be unknown (typically because of an error)
without OR itself returning an error. In such cases, OR
simply returns the value of the known operand. This is
equivalent to treating the unknown operand as FALSE.
This way, errors occurring during argument evaluation will not prevent the OR expression from being evaluated. This is different from evaluating the arguments and their OR in the same expression because expression evaluation is aborted when it results in an error; if the arguments are evaluated in the same expression as their OR, an error occurring during the evaluation of either argument will prevent the OR from being evaluated. Error-tolerant OR expressions can be used to check for the availability of data without ending up with an error condition if the data is not available. For instance, the function CROSSES will return an error if it can't find any threshold crossings. To check for this condition, assign the row count (function ROWS) of the result returned by CROSSES to a symbol, then OR that symbol with the constant FALSE. If the result is TRUE, it's safe to access the array returned by CROSSES; if not, there are no crossings. The error-tolerant functions IF and CHOOSE can be used to perform alternate operations in the two cases. |
|
| xor | Logical XOR (eXclusive OR). Form: A xor B Both operands are converted to booleans, then TRUE is returned if A <> B, i.e. if A is TRUE and B is FALSE, or if A is FALSE and B is TRUE. If A and B have the same boolean value, FALSE is returned. Built-in identifiers are not case sensitive. Hence "XOR", "Xor", "xor" are all equally valid spellings. XOR treats unknown
operands similarly to OR: if either operand is unknown,
XOR returns FALSE. This is equivalent to treating the
unknown operand as equal to the known operand.
This way, errors occurring during argument evaluation will not prevent the XOR expression from being evaluated. This is different from evaluating the arguments and their XOR in the same expression because expression evaluation is aborted when it results in an error; if the arguments are evaluated in the same expression as their XOR, an error occurring during the evaluation of either argument will prevent the XOR from being evaluated. |
|
| not | Logical NOT. Form: not A (unary). The operand is converted to boolean, then the opposite boolean value is returned (TRUE is A is FALSE, FALSE if A is TRUE). Built-in identifiers are not case sensitive. Hence "NOT", "Not", "not" are all equally valid spellings. |
| Operator | Meaning |
| & (ampersand) |
Concatenation. Form: A & B Both operands are converted to strings, then they are concatenated, i.e. the string representation of B's value is appended to the string representation of A's value. See also function CONCATENATE. |
| Operator | Meaning |
| : (colon) |
Cell range. Form: A:B Each operand must be a reference to a single cell. The operator returns a reference to the rectangular cell range spanned by corners A and B. It is customary, but not mandatory, to specify the upper left corner for A and the lower right corner for B. |
If an expression contains more than one operator, the order of evaluation is determined by the following operator precedence rules:
| Operator | Precedence |
| not, unary -, unary + | First (highest) |
| : | Second |
| ^ | Third |
| *, /, div, mod, and | Fourth |
| dyadic +, dyadic -, or, xor, & | Fifth |
| dyadic =, <>, <, >, <=, >= | Sixth |
| % | Seventh (lowest) |
| An
operator with higher precedence is evaluated before an
operator with lower precedence. Example: =2 + 2 div 3 is evaluated in two steps: first 2 div 3 = 0, then 0 + 2 = 2. This is because the integer division operator (div) takes precedence over the dyadic addition operator (+). |
|
| Operators
of the same precedence are evaluated from left to right (i.e.
leftmost operator first, rightmost operator last). Example: =1 - 2 + 3 is evaluated as 1 - 2 = -1, -1 + 3 = 2. This is because the dyadic subtraction (-) and addition (+) operators have the same precedence. |
|
| An
expression within parentheses is evaluated first, then
treated as a single operand. Parentheses override all
operator precedence rules. Example: =(2 + 2) div 3 is evaluated in the order 2 + 2 = 4, 4 div 3 = 1. This is in spite of integer division (div) having higher precedence than dyadic addition (+). |