Skip to main content

Comparison Primitives

TVM Instructions Content List

OpcodeFift syntaxStackDescriptionGas
Please enter a search query
No results found

Comparison Primitives

Integer comparison

xxxxxxx
Opcode
xxxxxxxxxxxxxxxxxxxxxxxxxxxx
Fift syntax
xxxxxxxxxxxxxxxxx
Stack
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Description
xxxx
Gas
B8SGNx - sgn(x)Computes the sign of an integer x:
-1 if x<0, 0 if x=0, 1 if x>0.
18
B9LESSx y - x<yReturns -1 if x<y, 0 otherwise.18
BAEQUALx y - x=yReturns -1 if x=y, 0 otherwise.18
BBLEQx y - x<=y18
BCGREATERx y - x>y18
BDNEQx y - x!=yEquivalent to EQUAL NOT.18
BEGEQx y - x>=yEquivalent to LESS NOT.18
BFCMPx y - sgn(x-y)Computes the sign of x-y:
-1 if x<y, 0 if x=y, 1 if x>y.
No integer overflow can occur here unless x or y is a NaN.
18
C0yy[yy] EQINTx - x=yyReturns -1 if x=yy, 0 otherwise.
-2^7 <= yy < 2^7.
26
C000ISZEROx - x=0Checks whether an integer is zero. Corresponds to Forth's 0=.26
C1yy[yy] LESSINT
[yy-1] LEQINT
x - x<yyReturns -1 if x<yy, 0 otherwise.
-2^7 <= yy < 2^7.
26
C100ISNEGx - x<0Checks whether an integer is negative. Corresponds to Forth's 0<.26
C101ISNPOSx - x<=0Checks whether an integer is non-positive.26
C2yy[yy] GTINT
[yy+1] GEQINT
x - x>yyReturns -1 if x>yy, 0 otherwise.
-2^7 <= yy < 2^7.
26
C200ISPOSx - x>0Checks whether an integer is positive. Corresponds to Forth's 0>.26
C2FFISNNEGx - x >=0Checks whether an integer is non-negative.26
C3yy[yy] NEQINTx - x!=yyReturns -1 if x!=yy, 0 otherwise.
-2^7 <= yy < 2^7.
26
C4ISNANx - x=NaNChecks whether x is a NaN.18
C5CHKNANx - xThrows an arithmetic overflow exception if x is a NaN.18/68

Other comparison

Most of these "other comparison" primitives actually compare the data portions of Slices as bitstrings (ignoring references if not stated otherwise).

xxxxxxx
Opcode
xxxxxxxxxxxxxxxxxxxxxxxxxxxx
Fift syntax
xxxxxxxxxxxxxxxxx
Stack
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Description
xxxx
Gas
C700SEMPTYs - ?Checks whether a Slice s is empty (i.e., contains no bits of data and no cell references).26
C701SDEMPTYs - ?Checks whether Slice s has no bits of data.26
C702SREMPTYs - ?Checks whether Slice s has no references.26
C703SDFIRSTs - ?Checks whether the first bit of Slice s is a one.26
C704SDLEXCMPs s' - xCompares the data of s lexicographically with the data of s', returning -1, 0, or 1 depending on the result.26
C705SDEQs s' - ?Checks whether the data parts of s and s' coincide, equivalent to SDLEXCMP ISZERO.26
C708SDPFXs s' - ?Checks whether s is a prefix of s'.26
C709SDPFXREVs s' - ?Checks whether s' is a prefix of s, equivalent to SWAP SDPFX.26
C70ASDPPFXs s' - ?Checks whether s is a proper prefix of s' (i.e., a prefix distinct from s').26
C70BSDPPFXREVs s' - ?Checks whether s' is a proper prefix of s.26
C70CSDSFXs s' - ?Checks whether s is a suffix of s'.26
C70DSDSFXREVs s' - ?Checks whether s' is a suffix of s.26
C70ESDPSFXs s' - ?Checks whether s is a proper suffix of s'.26
C70FSDPSFXREVs s' - ?Checks whether s' is a proper suffix of s.26
C710SDCNTLEAD0s - nReturns the number of leading zeroes in s.26
C711SDCNTLEAD1s - nReturns the number of leading ones in s.26
C712SDCNTTRAIL0s - nReturns the number of trailing zeroes in s.26
C713SDCNTTRAIL1s - nReturns the number of trailing ones in s.26

TVM Instructions Content List