Below is a complete list of all operators and what they do.
Operator | Type | Description | Overridable | Sample | Result |
---|---|---|---|---|---|
and | Binary | Boolean AND operator | ✓ | true and false |
false |
or | Binary | Boolean OR operator | ✓ | true or false |
true |
not | Unary | Boolean NOT operator | ✓ | not false |
true |
nand | Binary | Boolean NAND operator—shortcut for not (a or b) |
true nand false |
true |
|
nor | Binary | Boolean NOR operator—shortcut for not (a and b) |
false nor true |
false |
|
xor | Binary | Boolean XOR operator—shortcut for (a and not b) or (not a and b) |
false xor true |
true |
|
xnor | Binary | Boolean XNOR operator—shortcut for not a and not b |
false xnor true |
false |
|
band | Binary | Bitwise AND operator | |||
bor | Binary | Bitwise OR operator | |||
bnot | Unary | Bitwise NOT operator | |||
bnand | Binary | Bitwise NAND oeprator—shortcut for not(a bor b) |
|||
bnor | Binary | Bitwise NOR operator—shortcut for bnot (a band b) |
|||
bxor | Binary | Bitwise XOR operator—shortcut for (a band bnot b) bor (bnot a band b) |
|||
bxnor | Binary | Bitwise XNOR operator—shortcut for bnot a band bnot b |
|||
+ | Binary | addition operator | ✓ | 3 + 5 |
8 |
- | Binary | subtraction operator | ✓ | 3 - 5 |
-2 |
* | Binary | multiplication operator | ✓ | 3 * 5 |
15 |
/ | Binary | division operator | ✓ | 15 / 3 |
5 |
mod | Binary | modulus operator | 5 mod 3 |
2 |
|
div | Binary | integer division operator | 5 div 3 |
1 |
|
^ | Binary | mathematical exponential operator | ✓ | 3 ^ 2 |
9 |
& | Psuedo-unary | When this appears before the name of a procedure or property, returns a delegate instance to that procedure or property | |||
? | Type modifier | Turns a primitive (not structs or enums) into one that can be null—Except for boolean, this may add at least one byte to the storage needed | var ? int |
||
() | Inner-parameter | Parenthetical operator | |||
|| | Inner-parameter | Mathematical absolute value operator | |-5| |
5 |
|
[] | Type modifier | Turns a type into an array of the type | var int[] array = new int[3] |
||
[] | Inner-parameter | Array indexer | list[5] |
||
[] | Inner-parameter | (When used with new) allocates an array of size X | new String[5] |
||
{} | Type modifier | Turns a type into a set of that type | var int{} v = new int{} 5, 3, 7, 9 |
||
{} | Inner-parameter list | (When used with new) Used to write a set constant | new int{} 3, 5, 6, 34 new int{SomeFixedSetInstance} 5, 3, 6, 34 |
||
{}f | Type modifier | Turns a type into a fixed set | var int{}f fixed = new int{}f 3, 5, 9, 34</ocde> |
||
{}f | Inner-parameter list | (When used with new) Used to write a set constant that can't have other members—used to control what can be in normal sets | new int{}f 3, 5, 6, 23 |
||
. | Psuedo-binary | Used to access the members of a struct or class | name.member |
||
, | Pseudo-binary | Used to delimit lists when no custom keyword has been specified | |||
= | Binary | Assignment operator—copies the reference if this is a reference type—not valid for structs | a = b |
||
= | Binary | Equality comparison operator—compares only the reference if this is a reference type—not valid for structs | if a = b then |
||
<> ( or ><) | Binary | Inequality comparison operator—compares only the reference if this is a reference type—not valid for structs | if a <> b then |
||
<= (or =<) | Binary | Less than or equal comparison operator—Undefined by default for non-numeric types | ✓ | if a <= b then |
|
< | Binary | Less than comparison operator—Undefined by default for non-numeric types | ✓ | if a < b then |
|
>= (or =>) | Binary | Greater than or equal comparison operator—Undefined by default for non-numeric types | ✓ | if a >= b then |
|
> | Binary | Greater than comparison operator—Undefined by default for non-numeric types | ✓ | if a > b then |
|
@ | Psuedo-binary | Base class selector | base@ClassName |
||
++ | Unary | Increment operator | ✓ | x ++ |
|
++ | Binary | Increment operator | ✓ | x ++ y |
|
-- | Unary | Decrement operator | ✓ | x -- |
|
-- | Binary | Decrement operator | ✓ | x -- y |
This lists all operators in order of precedence, starting with the highest precedence operators:
, o{} {} [] () and or xor xnor nand nor * / + - & = ++ -- <> >< <= =< < >= => > band bor bxor bxnor bnand bnor not bnot @
ASIL allows comparison operators to be chained as long as the resulting expression forms a range. So 4 < a and a < 8
could be written as 4 < a < 8
. This is meant to be transparent to those overriding these operators. Below are some samples of situations that can or can’t be combined.
a < b and b < c ' Not a range as there aren’t any constants 4 < b and c > 8 ' Not a range as the operators don’t “point” in the same direction 4 < b and b <= 8 ' Valid range as the operators agree so this could be “4 < b < 8”
You can also chain equality operators as shown below.
(a = b = c) = (a = b and a = c) ' This will always be true
Something like a = b = c
will attempt to set a
and b
to the value of c
. If you need to force “b = c” to be a comparison, use the syntax provided in the next section.
If ASIL gives you the wrong operator, you can call it with something like typename.+ parameterlist
. The code below shows how to set a boolean to the result of a comparison.
Note: The assignment operator can’t be selected this way. This is deliberate and prevents you from making assignments when you wanted a comparison.
var boolean b = c% = d% ' wrong var boolean b = int.= c%, d% ' correct
Some comparison operators can be referenced with either of two “names”. Those are listed in the table below. The “type” part is a placeholder for the real type name.
Name 1 | Name 2 |
---|---|
type.<> | type.>< |
type.<= | type.=< |
type.=> | type.>= |
Wiki: Custom operators
Wiki: Home
Wiki: keywords-operator
Wiki: operators-abs
Wiki: operators-addition
Wiki: operators-amp
Wiki: operators-and
Wiki: operators-at
Wiki: operators-band
Wiki: operators-bnand
Wiki: operators-bnor
Wiki: operators-bnot
Wiki: operators-bor
Wiki: operators-braces
Wiki: operators-bracesf
Wiki: operators-brackets
Wiki: operators-bxnor
Wiki: operators-bxor
Wiki: operators-can-be-null
Wiki: operators-comma
Wiki: operators-dec
Wiki: operators-div
Wiki: operators-equals
Wiki: operators-exponential
Wiki: operators-float-division
Wiki: operators-gt-equal
Wiki: operators-gt
Wiki: operators-inc
Wiki: operators-inequality
Wiki: operators-lt-equal
Wiki: operators-lt
Wiki: operators-member-access
Wiki: operators-minus
Wiki: operators-mod
Wiki: operators-multiplication
Wiki: operators-nand
Wiki: operators-nor
Wiki: operators-not
Wiki: operators-or
Wiki: operators-paren
Wiki: operators-xnor
Wiki: operators-xor