Operators
This guide covers all operators available in Ursus, organized by category with precedence levels and examples.
Operator Precedence Table
| Level | Operator | Description | Example |
|---|---|---|---|
| 1 | x++, x-- | Post-increment/decrement | count++ |
| 1 | array[index] | Array/mapping access | balances[addr] |
| 1 | obj.field | Member access | msg->sender |
| 1 | func(args) | Function call | transfer(addr, amt) |
| 2 | ++x, --x | Pre-increment/decrement | ++count |
| 2 | !x | Logical NOT | !isActive |
| 2 | ~x | Bitwise NOT | ~flags |
| 3 | x ** y | Exponentiation | base ** exp |
| 4 | x * y | Multiplication | price * qty |
| 4 | x / y | Division | total / count |
| 4 | x % y | Modulo | value % 10 |
| 5 | x + y | Addition | a + b |
| 5 | x - y | Subtraction | a - b |
| 6 | x << y | Left shift | flags << 2 |
| 6 | x >> y | Right shift | value >> 8 |
| 7 | x & y | Bitwise AND | a & mask |
| 8 | x ^ y | Bitwise XOR | a ^ b |
| 9 | x | y | Bitwise OR | a | b |
| 10 | x < y, x <= y | Less than, less or equal | a < b |
| 10 | x > y, x >= y | Greater than, greater or equal | a > b |
| 11 | x == y | Equal | a == b |
| 11 | x != y | Not equal | a != b |
| 12 | x && y | Logical AND | a && b |
| 13 | x || y | Logical OR | a || b |
| 14 | cond ? a : b | Ternary conditional | x > 0 ? x : -x |
| 14 | x := y | Assignment | balance := 100 |
| 14 | x += y, x -= y | Compound assignment | count += 1 |
| 14 | x &= y, x |= y | Bitwise compound | flags |= bit |
Arithmetic Operators
Basic Arithmetic
Addition (+):
x + y
Type rules:
uint + uint→uint(larger type)int + int→int(larger type)uint + int→int
Overflow behavior: Wraps around (modulo 2^n)
Example:
::// var total : uint256 := balance + amount |.
::// var delta : int256 := profit + loss |.
Subtraction (-):
x - y
Same type rules as addition.
Example:
::// var remaining : uint256 := total - spent |.
Multiplication (*):
x * y
Example:
::// var cost : uint256 := price * quantity |.
Division (/):
x / y
Special behavior: If y == 0, result is 0 (no exception)
Example:
::// var average : uint256 := sum / count |.
Modulo (%):
x % y
Special behavior: If x == 0, result is 0
Example:
::// var remainder : uint256 := value % {10} |.
Increment/Decrement
Post-increment:
x++
Pre-increment:
++x
Post-decrement:
x--
Pre-decrement:
--x
Example:
::// counter++ .
::// --index .
Comparison Operators
Equal (==):
x == y
Not equal (!=):
x != y
Less than (<):
x < y
Less or equal (<=):
x <= y
Greater than (>):
x > y
Greater or equal (>=):
x >= y
Example:
::// if (balance >= amount) then { ->> } else { ->> } |.
{
::// transfer(recipient, amount) |.
}
{
::// revert("Insufficient balance") |.
}
Logical Operators
Logical AND (&&):
x && y
Logical OR (||):
x || y
Logical NOT (!):
!x
Example:
::// if (isActive && !isPaused) then { ->> } |.
{
::// execute() |.
}
Bitwise Operators
Bitwise AND (&):
x & y
Bitwise OR (|):
x | y
Bitwise XOR (^):
x ^ y
Bitwise NOT (~):
~x
Left shift (<<):
x << y
Right shift (>>):
x >> y
Example:
::// var masked : uint256 := value & mask |.
::// var shifted : uint256 := flags << {8} |.
::// var combined : uint256 := a | b |.
Bit Size Functions (Everscale)
bitSize - Signed bit size:
\\ bitSize(x) \\
Computes smallest c ≥ 0 such that x fits in c-bit signed integer (−2^(c−1) ≤ x < 2^(c−1))
uBitSize - Unsigned bit size:
\\ uBitSize(x) \\
Computes smallest c ≥ 0 such that x fits in c-bit unsigned integer (0 ≤ x < 2^c)
Example:
::// var bits : uint256 := uBitSize(value) ;_|.
Compound Assignment
Addition assignment (+=):
x += y (* Equivalent to: x := x + y *)
Subtraction assignment (-=):
x -= y (* Equivalent to: x := x - y *)
Bitwise OR assignment (|=):
x |= y (* Equivalent to: x := x | y *)
Bitwise AND assignment (&=):
x &= y (* Equivalent to: x := x & y *)
Example:
::// balance += amount .
::// counter -= {1} .
::// flags |= NEW_FLAG .
Ternary Operator
Conditional expression:
condition ? true_value : false_value
Example:
::// var result : uint256 := (x > {0}) ? x : {0} |.
::// var status : string := isActive ? "Active" : "Inactive" |.
See Also
- Functions - Standard library functions
- Primitives - Basic types
- Function Operators - Statement operators