Skip to content

Commit 69bb7a1

Browse files
committed
Operators
1 parent ea0c603 commit 69bb7a1

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

docs/operators.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,62 @@ slug: /operators
33
---
44

55
# Operators
6+
7+
## Arithmetic
8+
9+
### Binary
10+
11+
| Op | Example | Description |
12+
| --- | ------- | ------------------------------------------------------ |
13+
| `+` | `1 + 2` | Adds two `Int` values and returns the sum. |
14+
| `-` | `1 - 2` | Subtracts two `Int` values and returns the difference. |
15+
| `*` | `2 * 2` | Multiplies two `Int` values and return the product. |
16+
| `/` | `4 / 2` | Divides two `Int` values and returns the quotient. |
17+
| `%` | `3 % 2` | Divides two `Int` values and returns the remainder. |
18+
19+
### Unary
20+
21+
| Op | Example | Description |
22+
| --- | ------- | -------------------------------------------------- |
23+
| `+` | `+42` | An unnecessary no-op. |
24+
| `-` | `-42` | Returns the negative equivalent of an `Int` value. |
25+
26+
## Bytes
27+
28+
| Op | Example | Description |
29+
| --- | ----------- | -------------------------------------------------- |
30+
| `+` | `"A" + "B"` | Concatenates two values with the `Bytes` together. |
31+
32+
## Bitwise
33+
34+
| Op | Example | Description |
35+
| ---- | ----------- | ------------------------------------------------------- |
36+
| `<<` | `42 << 2` | Shifts the bits of the left hand side to the left. |
37+
| `>>` | `42 >> 2` | Shifts the bits of the left hand side to the right. |
38+
| `~` | `~42` | Performs a bitwise NOT on the bits of the `Int` value. |
39+
| `&` | `42 & 100` | Performs a bitwise AND on the bits of the `Int` values. |
40+
| `\|` | `42 \| 100` | Performs a bitwise OR on the bits of the `Int` values. |
41+
| `^` | `42 ^ 100` | Performs a bitwise XOR on the bits of the `Int` values. |
42+
43+
## Logical
44+
45+
| Op | Example | Description |
46+
| ------ | ----------------- | ------------------------------------------------- |
47+
| `!` | `!true` | Returns `true` if `false`, and `false` if `true`. |
48+
| `&&` | `true && false` | Lazy evaluates if both `Bool` values are `true`. |
49+
| `\|\|` | `true \|\| false` | Lazy evaluates if either `Bool` value is `true`. |
50+
| `&` | `true & false` | Returns whether both `Bool` values are `true`. |
51+
| `\|` | `true \| false` | Returns whether either `Bool` value is `true`. |
52+
53+
## Comparison
54+
55+
| Op | Example | Description |
56+
| ---- | -------- | ------------------------------------------------------------ |
57+
| `<` | `1 < 2` | If the left side is less than the right side. |
58+
| `>` | `1 > 2` | If the left side is greater than the right side. |
59+
| `<=` | `1 <= 2` | If the left side is less than or equal to the right side. |
60+
| `>=` | `1 >= 2` | If the left side is greater than or equal to the right side. |
61+
62+
:::note
63+
The comparison operators can also be used with `Bytes` values, and the special byte-specific `>s` operator is used to implement this in [CLVM](https://chialisp.com/operators/#comparison).
64+
:::

0 commit comments

Comments
 (0)