Files
fz-lang/docs/en/reference/operators.md
T

38 lines
1.9 KiB
Markdown

# Operators
FZLang supports arithmetic, comparison, logical, and unary operations. During execution, a binary operation takes two values from the stack and puts its result back. A unary operation takes one value from the stack and puts its result back.
## Arithmetic operations
| Operation | Supported types | Description |
| --------- | --------------- | ----------- |
| `N + N` | *all numeric types* | Add two operands |
| `N - N` | *all numeric types* | Subtract the right operand from the left |
| `N * N` | *all numeric types* | Multiply two operands |
| `N / N` | *all numeric types* | Divide the left operand by the right |
| `N % N` | *all numeric types* | Remainder of the left operand divided by the right |
| `N ^ N` | *all numeric types* | Raise the left operand to the power of the right |
| `-N` | *all numeric types* | Negate the operand |
## Comparison operations
| Operation | Supported types | Description |
| --------- | --------------- | ----------- |
| `N == N` | *all numeric types*, booleans, objects, strings | Check whether the operands are equal |
| `N != N` | *all numeric types*, booleans, objects, strings | Check whether the operands are unequal |
| `N > N` | *all numeric types* | Check whether the left operand is greater than the right |
| `N >= N` | *all numeric types* | Check whether the left operand is greater than or equal to the right |
| `N < N` | *all numeric types* | Check whether the left operand is less than the right |
| `N <= N` | *all numeric types* | Check whether the left operand is less than or equal to the right |
| `!N` | booleans | Invert the operand |
> **Important:** Comparing objects with `==` or `!=` compares their addresses, not their values.
## Logical operations
| Operation | Supported types | Description |
| --------- | --------------- | ----------- |
| `N && N` | booleans | Logical **AND** of two operands |
| `N || N` | booleans | Logical **OR** of two operands |