# Operators

An infix * operator *is a symbol, such as a plus sign (

`1 + 2`

) or product (`10*2`

), that operates on the values before and after it. A prefix operator, such as unary minus (`-100`

) operates only on the value after it. Analytica includes these fairly standard opera tors, including arithmetic, comparison, and logical operators:
### Arithmetic operators

The arithmetic operators apply to numbers and produce numbers:

Operator Meaning Examples x+y plus [math]\displaystyle{ 3 + 2 → 5 }[/math] x - y binary minus [math]\displaystyle{ 3 - 2 → 1 }[/math] -x unary minus [math]\displaystyle{ -2 → -2 }[/math] x*y product [math]\displaystyle{ 3*2 → 6 }[/math] x/3 or x÷y division [math]\displaystyle{ 3/2 (= \frac{3}{2}) → 1.5 }[/math] x^y to the power of [math]\displaystyle{ 3^2 = 3^2 → 9 }[/math] [math]\displaystyle{ 4^.5 = 4^{\frac{1}{2}} → 2 }[/math]

### Text concatenation

The text concatenation operator, `&`

joins the sequence of characters from each parameter to form a text result. If either parameter is not already text, then the value is *coerced* to text using the number format for the object containing the expression. If you use the operator in a user-defined function then the function's number format is used.

Operator Meaning Examples a & b concatenate `'foo' & 'bar' → 'foobar'`

`'pi=' & Pi → 'pi=3.142'`

`(1/5) & (7^2) → '0.249'`

The last two examples shown may be different when the current object's number format is different at the time the expression is evaluated. For example, when Fixed Point, 3 digits with trailing zeroes is used,

`'pi=' & Pi → 'pi=3.14'`

`(1/5) & (7^2) → '0.2049.00'`

When coercing numbers to text, you can instead use the NumberToText function, so that the number format actually used is explicit in the expression.

`'pi=' & NumberToText(Pi, 'Suffix', digits:15) → 'pi=3.14159265358979'`

### Comparison operators

Comparison operators apply to numbers and text values and produce Boolean values.

Operator Meaning Examples → (1 = true, 0 = false) < less than `2 < 2`

`'A' < 'B'`

`→ 0`

`→ 1`

<= less than or equal to `2 <= 2`

`'ab' <= 'ab'`

`→ 1`

`→ 1`

= equal to `100 = 101`

`'AB' = 'ab'`

`→ 0`

`→ 0`

>= greater than or equal to `100 >= 1`

`'ab'> = 'cd'`

`→ 1`

`→ 0`

> greater than `1 > 2`

`'A' > 'a'`

`→ 0`

`→ 1`

<> not equal to `1 <> 2`

`'A' <> 'B'`

`→ 1`

`→ 1`

### Alphabetic ordering of text values

You can apply the comparison operators, <. >, >=, <=, or sorting functions, SortIndex(d, i), Sort(d, i) and Rank(), to text values. They generally use alphabetical order as in a dictionary, so:

`'Analytica' < 'Excel' → 1 (True)`

These operators and functions are normally case sensitive, so uppercase letters precede lowercase letters:

`'Analytica' > 'excel' → 0 (False)`

If you want alphabetic ordering to ignore case, use TextUpperCase() or TextLowerCase() to convert all letters to the same case.

`TextUpperCase('Analytica') < TextUpperCase('excel') → 1 (True)`

In functions, SortIndex(d, i), Sort(d, i) and Rank(), you can set their optional parameter «caseInsensitive» to True if you want them to ignore case.

Usually, digits precede letters:

`'9' < 'A' → 1 (True)`

The collation order of characters is region-specific collation, according to your language and country. It is determined by the `TextLocale`

system variable. If you want to see or change the collation order, bring up the Object window for `TextLocale`

by selecting it from the Definition → System Variables submenu, 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`

.

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.

### Logical operators

Logical operators apply to Boolean values and produce Boolean values.

Operator Meaning Examples *b1*AND*b2*true if both and`b1`

are true,`b2`

otherwise false

`5 > 0 AND 5 > 10`

`→`

`False`

*b1*OR*b2*true if or`b1`

or both are true,`b2`

otherwise false

`5 > 0 OR 5 > 10`

`→`

`True`

`NOT`

*b*true if is false,`b`

otherwise false

`NOT (5 > 0)`

`→`

`False`

### 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’s`Irr`

function`Irr(Payments, Time)`

The built-in function

### Operator binding precedence

Analytica uses a standard precedence hierarchy resolves potential ambiguity when evaluating operators in expressions with multiple operators. For example,

`1/2*3 - 3^2 + 4`

is interpreted as:

`(((1/2)*3) - (3^2)) + 4`

It binds arithmetic operators before comparison operators and comparison operators before logical operators, and all of these before IF...THEN...ELSE ... and other language constructs, so:
`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)`

The binding precedence for operators, from most tightly bound to least tightly bound, is:

- parentheses ()
- function calls
- @I, \A, \[I]A, #R.
- A.I
- obj->member (COM Integration)
- Not
- 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). For example,

`1/2*3`

is interpreted as:

`(1/2)*3`

not as

`1/(2*3)`

## See Also

Enable comment auto-refresher