# Operators (https://docs-fpm2731fy-ton-core-docs.vercel.app/llms/tolk/syntax/operators/content.md)



Tolk provides standard operators for integers and booleans.

## Operator priority [#operator-priority]

From highest to lowest.

### Parenthesis `(` `)` [#parenthesis--]

Groups expressions: `(1 + 2) * 3`; or creates [tensors](/llms/languages/tolk/types/tensors/content.md): `pair = (1, 2)`.

### Square brackets `[` `]` [#square-brackets--]

A universal constructor `[1, 2]` creates an array, `lisp_list`, or shaped tuple. See [tuples](/llms/languages/tolk/types/tuples/content.md).

### Operator `lazy` [#operator-lazy]

With [lazy loading](/llms/languages/tolk/features/lazy-loading/content.md) the compiler loads only the accessed fields and skips the rest.

### Non-null assertion operator `!` [#non-null-assertion-operator-]

Skips the [nullability](/llms/languages/tolk/types/nullable/content.md) check: `someVar!`.

### Unary operators `!` `~` `-` `+` [#unary-operators-----]

[Logical negation](/llms/languages/tolk/types/booleans/content.md) `!x` (requires a `bool`), bitwise not `~x`, unary `-x` and `+x`.

### Operators `as` `is` `!is` [#operators-as-is-is]

[Unsafe `as` cast](/llms/languages/tolk/types/type-checks-and-casts/content.md) and checks for [union types](/llms/languages/tolk/types/unions/content.md): `someVar is int`.

### Multiplicative `*` `/` `%` `^/` `~/` [#multiplicative-----]

Integer multiplication, division, modulo, ceiling-division, and rounding-division. All [integers](/llms/languages/tolk/types/numbers/content.md) have 257-bit precision.

### Additive `+` `-` [#additive---]

Standard integer addition and subtraction.

### Shifts `<<` `>>` `^>>` `~>>` [#shifts----]

Bitwise shifts, extended by ceiling-right and rounding-right.

### Comparison `==` `<` `>` `<=` `>=` `!=` `<=>` [#comparison-------]

Comparison operators. `<=>` is known as the spaceship or sign operator. Operators `==` and `!=` also work for several non-numeric types. For example, [addresses](/llms/languages/tolk/types/address/content.md).

### Bitwise `&` `|` `^` [#bitwise---]

Standard bitwise operators, applicable to both integers and booleans.

### Logical `&&` `||` [#logical--]

[Short-circuit](/llms/languages/tolk/types/booleans/content.md): the right operand is evaluated only when necessary.

### Assignment `=` `+=` `-=` and other [#assignment-----and-other]

Assignment and augmented assignments.

### Null-coalescing `??` [#null-coalescing-]

Returns the left operand if it is not `null`; otherwise, evaluates and returns the right operand. See [nullable types](/llms/languages/tolk/types/nullable/content.md).

### Ternary `... ? ... : ...` (same priority) [#ternary------same-priority]

Ternary expressions are available in [conditions](/llms/languages/tolk/syntax/conditions-loops/content.md).

## Missing operators [#missing-operators]

Tolk does not support `i++` and `i--`. Use `i += 1` and `i -= 1` instead.

## Warnings on unexpected precedence [#warnings-on-unexpected-precedence]

A common pitfall:

```tolk
if (flags & 0xFF != 0) {
    // ...
}
```

This does not check the lowest byte. It is parsed as `flags & (0xFF != 0)`, because `!= ` has higher precedence, as in C++.

To prevent such cases, the compiler reports an error:

```ansi
error: & has lower precedence than !=, probably this code won't work as you expected.
       Use parenthesis: either (... & ...) to evaluate it first, or (... != ...) to suppress this error.

   2 |     if (flags & 0xFF != 0) {
     |         ^^^^^^^^^^^^^^^^^
```
