Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Operators

This guide covers all operators available in Ursus, organized by category with precedence levels and examples.

Operator Precedence Table

LevelOperatorDescriptionExample
1x++, x--Post-increment/decrementcount++
1array[index]Array/mapping accessbalances[addr]
1obj.fieldMember accessmsg->sender
1func(args)Function calltransfer(addr, amt)
2++x, --xPre-increment/decrement++count
2!xLogical NOT!isActive
2~xBitwise NOT~flags
3x ** yExponentiationbase ** exp
4x * yMultiplicationprice * qty
4x / yDivisiontotal / count
4x % yModulovalue % 10
5x + yAdditiona + b
5x - ySubtractiona - b
6x << yLeft shiftflags << 2
6x >> yRight shiftvalue >> 8
7x & yBitwise ANDa & mask
8x ^ yBitwise XORa ^ b
9x | yBitwise ORa | b
10x < y, x <= yLess than, less or equala < b
10x > y, x >= yGreater than, greater or equala > b
11x == yEquala == b
11x != yNot equala != b
12x && yLogical ANDa && b
13x || yLogical ORa || b
14cond ? a : bTernary conditionalx > 0 ? x : -x
14x := yAssignmentbalance := 100
14x += y, x -= yCompound assignmentcount += 1
14x &= y, x |= yBitwise compoundflags |= bit

Arithmetic Operators

Basic Arithmetic

Addition (+):

x + y

Type rules:

  • uint + uintuint (larger type)
  • int + intint (larger type)
  • uint + intint

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