The following mathematical operations are supported:
Symbol | Arity | Description |
+ | binary | addition |
- | unary | negation |
- | binary | subtraction |
+ + | unary | pre- and post-increment |
- - | unary | pre- and post-decrement |
* | binary | multiplication |
/ | binary | division |
% | binary | remainder, e.g., 5%3 = 2 |
^ | binary | power, x ^ y = x to power y |
& , and | binary | and, value is 1 if both operands are nonzero |
| , or | binary | or, value is 1 if either operand is nonzero |
! , ~ , not | unary | not, value is 1/0 if operand is zero/nonzero |
> , gt | binary | greater than, value is 1 if left operand is greater than the right |
> = , ge | binary | greater or equal, value is 1 if left operand is greater or equal to the right |
< , lt | binary | less than, value is 1 if the left operand is less than the right |
< = , le | binary | less or equal, value is 1 if the left operand is less than or equal to the right |
! = , ne , < > , > < | binary | not equal, value is 1 if the left operand is not equal to the right |
= = , eq | binary | equal, value is 1 if the left operand is equal to the right |
---|---|---|
= | binary | the left operand takes the value of the right, and the value is that of the right operand. The type of the left operand becomes that of the right. |
The operator-equivalent keywords (gt, lt, ge, le, ne, eq, or, and, not) are recognized without case sensitivitty.
A variable type is determined by its first assignment, of by declaration for arrays. It is generally an error to attempt to redefine a variable to a different type, though if a scalar is assigned from a handle, the scalar type is promoted to handle type.
Note that all operators, including assignment, return a value. Thus, expressions like 3*(x > y) make sense (the value is 0 or 3). Binary truth is indicated by a nonzero value.
The increment/decrement operators (++/-) behave as in the C language. That is
y = x + + is equivalent to y = x;x = x + 1
y = x - - is equivalent to y = x;x = x - 1
y = + + x is equivalent to x = x + 1;y = x
y = x - - is equivalent to x = x - 1;y = x
All of these operations apply to scalar or complex values. If complex and scalar values are mixed, scalar operands are promoted to complex with zero imaginary value. If a complex operand is given, the result is also complex, except for comparison and logical operators, and modulus, which always return scalar values. Comparison operators are applied to both real and imaginary parts, and both must separately satisfy the relation. Increment and decrement operations apply only to the real part of a complex value. In logical operations, a complex value is ``false'' if both the real and imaginary parts are 0.