Arithmetic Operators
Morph supports standard arithmetic operations plus a special matrix multiplication operator.
Operators
| Operator | Description | Example |
|---|---|---|
+ | Addition | a + b |
- | Subtraction | a - b |
* | Multiplication | a * b |
/ | Division | a / b |
@ | Matrix multiplication | A @ B |
++ | Increment | i++ |
-- | Decrement | i-- |
Basic Arithmetic
x is 10;
y is 3;
sum is x + y; // 13
diff is x - y; // 7
product is x * y; // 30
quotient is x / y; // 3
Increment and Decrement
counter is 0;
counter++; // counter is now 1
counter--; // counter is now 0
These are commonly used in for loops:
for(i is 0; i < 10; i++) {
Print(i);
}
Matrix Multiplication (@)
The @ operator performs matrix multiplication on tensors:
A is Tensor<float>.Random(2, 2);
B is Tensor<float>.Random(2, 2);
C is A @ B; // matrix multiplication
See Tensor Operations for details.
Operator Precedence
From highest to lowest:
!(not), unary-*,/,@+,-==,!=,>,<,>=,<=&&||
Use parentheses to override precedence:
result is (a + b) * c;