Skip to main content

Operators

Arithmetic

Binary

OpExampleDescription
+1 + 2Adds two Int values and returns the sum.
-1 - 2Subtracts two Int values and returns the difference.
*2 * 2Multiplies two Int values and return the product.
/4 / 2Divides two Int values and returns the quotient.
%3 % 2Divides two Int values and returns the remainder.
note

The + operator can be used with Bytes values to concatenate them together.

The +, -, and * operators can be used with PublicKey or Signature values to perform the corresponding BLS math operations (ie point addition, subtraction, or multiplication).

Unary

OpExampleDescription
++42An unnecessary no-op.
--42Returns the negative equivalent of an Int value.
note

The - operator can be used with PublicKey or Signature values to negate them.

Bitwise

OpExampleDescription
<<42 << 2Shifts the bits of the left hand side to the left.
>>42 >> 2Shifts the bits of the left hand side to the right.
~~42Performs a bitwise NOT on the bits of the Int value.
&42 & 100Performs a bitwise AND on the bits of the Int values.
|42 | 100Performs a bitwise OR on the bits of the Int values.
^42 ^ 100Performs a bitwise XOR on the bits of the Int values.

Logical

OpExampleDescription
!!trueReturns true if false, and false if true.
&&true && falseLazy evaluates if both Bool values are true.
||true || falseLazy evaluates if either Bool value is true.
&true & falseReturns whether both Bool values are true.
|true | falseReturns whether either Bool value is true.

Comparison

OpExampleDescription
<1 < 2If the left side is less than the right side.
>1 > 2If the left side is greater than the right side.
<=1 <= 2If the left side is less than or equal to the right side.
>=1 >= 2If the left side is greater than or equal to the right side.
note

The comparison operators can also be used with Bytes values, and the special byte-specific >s operator is used to implement this in CLVM.

Equality

OpExampleDescription
==1 == 2If the left side is equal to the right side.
!=1 != 2If the left side is not equal to the right side.