Sampi can also do math.
| Operation | Example | Result |
|---|---|---|
| Addition | 1 + 1 | 2 |
| Subtraction | 3 - 1 | 2 |
| Multiplication | 2 * 4 | 8 |
| Division | 8 / 2 | 4 |
| Exponentiation | 3^2 | 9 |
| Negation | ~3 | -3 |
Math in Sampi is a littel strange. ~3 gives -3. You can't simply use -3. The biggest change is the loss of the order
of operations. Normally, 2 + 3 * 4 will return 14 (2 + (3 * 4)), but in Sampi, it just goes left to right, so
2 + 3 * 4 is 20 ((2 + 3) * 4). This is very important when chaining conditions. These are the comparisons and how to
chain them.
| Comparison | Example | Result |
|---|---|---|
| Equal | 1 = 1 | true |
| Greater than | 2 > 1 | true |
| Less than | 2 < 3 | true |
| Greater than or equal to | 1 >= 1 | true |
| Less than or equal to | 1 <= 2 | true |
| Not equal | 1 != 2 | true |
| Operation | Example | Result |
|---|---|---|
| And | true and false | false |
| Or | true or false | true |
| Not | not true | false |
Condition chaining is when left to right evaluation can be annoying. If you type:
say(1 = 1 and 2 = 2)
You will get an error! But why? It is because instead of doing it like this: (1 = 1) and (2 = 2),
Sampi evaluates it this way: ((1 = 1) and 2) = 2. It tries to see if 1 = 1 and 2, which is invalid. The
fix is to run:
say(1 = 1 and (2 = 2))
Now it evaluates the code: (1 = 1) and (2 = 2), which is what we want! When chaining comparisons,
always use parentheses.