Operators
An operator is a symbol, such as a plus sign (+), that represents a computational operation or action such as addition or comparison. Analytica includes the following sets of standard opera- tors.
Arithmetic operators: The arithmetic operators apply to numbers and produce numbers:
Operator | Meaning | Examples |
---|---|---|
x+y | plus | 3+2→5 |
x-y | binary minus | 3-2→1 |
-x | unary minus | -2→-2 |
x*y | product | 3*2→6 |
x/3 or x÷y | division | 3/2 (=3÷2)→1.5 |
x^y | to the power of | 3^2=32 →9
4^.5 =41÷2 →2 |
Comparison operators: Comparison operators apply to numbers and text values and produce Boolean values.
Alphabetic ordering of text values: When applied to text values, the comparison operators, >, >=, >=, and <, use a region-specific collation order which takes into account conventions used in your own language and country. The specific collation order used is determined by the TextLocale
system variable. If you want to change the collation order, bring up the Object Window for TextLocale
by selecting it from the Definition →System Variables menu, with nothing selected and while in edit mode.
In general, the ordering of text may be different from the ordering implied by the numeric ASCII codes of the characters. For example, 'de' < 'dé' < 'df'
, whereas the ASCII code for 'é'
comes after the ASCII code for 'f'
. If you want text comparisons to use simple ASCII ordering, you can set TextLocale
to be ANSI
.
Generally, comparisons follow the ordering you would find in a dictionary. For example:
'Analytica' < 'Excel' →1 (True)
In almost all collation orders, digits precede letters:
'9' < 'A' →1 (True)
The comparison operators are case-sensitive, so that uppercase letters precede lowercase letters:
'Analytica' > 'excel' → 0 (False)
If you want to alphabetize without regard to case, use TextUppercase
or TextLowerCase
to convert letters to the same case.
TextUpperCase('Analytica') < TextUpperCase('excel') →1 (True)
When two text values do not contain identical character sequences, they are considered to be unequal, even if they represent the exact same text. This can happen in Unicode with combining characters. For example, an accented 'é' can be either Chr(233)
or Chr(769)&'e'
, where the Unicode Chr(769)
is the combining acute accent, which modifies the character that follows. Although these alternate representations of 'é'
are non-equal, they will have the same inequality comparisons with all other text, as if they are as closely adjacent in the sort order as is possible.
Sortindex(d,i), Sort(d,i) and Rank() also use the same collation ordering to determine the ordering of text values. Each also has an optional parameter to compare them in a case-insensitive fashion.
Logical operators: Logical operators apply to Boolean values and produce Boolean values.
Scoping operator (::): It is possible that a model created in a previous release might contain a variable or function with the same identifier as a new built-in variable or function. In this situation, an identifier name appearing in an expression might be ambiguous.
Prepending ::
to the name of a built-in function causes the reference to always refer to the built-in function. Otherwise, the identifier refers to the user’s variable or function. With this convention, existing models are not changed by the introduction of new built-in functions.
Example: Suppose a model from an older release of Analytica contains the user-defined function Irr(Values, I)
. Then:
Irr(Payments, Time)
User’sIrr
function::Irr(Payments, Time)
The built-in function
Operator binding precedence
A precedence hierarchy resolves potential ambiguity when evaluating operators and expressions. The precedence for operators, from most tightly bound to least tightly bound is:
- parentheses ()
- function calls
- Not
- @I, \A, \[I]A, #R.
- A.I
- A[I=x]
- Attrib of Obj
- ^
- - (unary, negative)
- *, /
- +, - (binary, minus)
- m..n
- <, >, <=, >=, =, <>
- And
- Or
- & (text concatenation)
- :=
- If … Then … Else, Ifonly … Then … Else, Ifall … Then … Else
- Sequence of statements separated by semicolons, sequence of elements or parameters separated by commas
Within each level of this hierarchy, the operators bind from left to right (left associative).
Examples: The following arithmetic expression:
1 / 2 * 3 - 3 ^ 2 + 4
is interpreted as:
((1 / 2) * 3) - (3 ^ 2) + 4
The following logical (Boolean) expression:
IF d + e < f ^ g or a and b > c THEN x ELSE y + z
is interpreted as:
IF (((d + e) < (f ^ g)) or (a and (b > c))) THEN x ELSE (y + z)
Enable comment auto-refresher