Skip to main content

Arithmetic

a + b

a - b

- a

a * b

a / b

a div b

Returns the euclidean quotient of two a divided by b; a div b is equivalent to:

match a /% b with
| some(q,r) -> q
| none -> fail("DIV_BY_ZERO")
end

Fails with

"DIV_BY_ZERO"

when b is equal to 0

a % b

Returns the euclidean remainder of a divided by b (modulus); a % b is equivalent to:

match a /% b with
| some(q,r) -> r
| none -> fail("DIV_BY_ZERO")
end

Fails with

"DIV_BY_ZERO"

when b is equal to 0

a /% b

Returns the euclidean division of a by b; returns an option of quotient and remainder:
  • some(q, r), when b is different from 0, q being the quotient and r the remainder
  • none, when b is equal to 0

Type of a

Type of b

Type of a /% b


option<nat * nat>


option<int * nat>


option<nat * tez>


option<int * nat>


option<int * nat>


option<tez * tez>

Fails with

does not fail

a <<| b

Shifts the bits of a to the left by the number of positions specified by b. Simultaneously, the empty spaces created by the bits shifted to the left are then filled with zeroes. It is a fast way to multiply by a power of 2.

Type of a

Type of b

Type of a <<| b

Fails with

"script_overflow"

when b is greater than 256

a |>> b

Shifts the bits of a to the right by the number of positions specified by b. It is a fast way to divide by a power of 2.

Type of a

Type of b

Type of a |>> b

Fails with

"script_overflow"

when b is greater than 256

a and b

Shortcut evaluation of logical conjonction:
  • true if a and b are true
  • false otherwise.

Type of a

Type of b

Type of a and b

Fails with

does not fail

a or b

Shortcut evaluation of logical disjonction:
  • true if a or b is true
  • false otherwise

Type of a

Type of b

Type of a or b

Fails with

does not fail

a xor b

  • true if a and b are different
  • false otherwise

Type of a

Type of b

Type of a xor b

Fails with

does not fail

not a

  • true if a is false
  • false if a is true

Type of a

Type of not a

Fails with

does not fail

a = b

a <> b

a < b

a <= b

a > b

a >= b

a <=> b

Comparison operator on which above comparison operators are built; it returns:
  • -1 when a < b
  • 1 when a > b
  • 0 when a = b

Fails with

does not fail

a < b < c

Double inequality operators are syntactic shortcuts for logical conjonction of two comparisons:

Equivalence


a < b < c

a < b and b < c


a <= b < c

a ≤ b and b < c


a < b <= c

a < b and b ≤ c


a <= b <= c

a ≤ b and b ≤ c