Comparison Primitives
TVM Instructions Content List
- Overview
- Stack Manipulation
- Tuple, List and Null
- Constants and Literals
- Arithmetic Operations
- Data Comparison
- Cell Manipulation
- Continuation and Control Flow
- Exception Generation and Handling
- Dictionary Manipulation
- Application-specific Primitives
- Miscellaneous
Opcode | Fift syntax | Stack | Description | Gas |
---|---|---|---|---|
Please enter a search query | ||||
No results found |
Comparison Primitives
Integer comparison
xxxxxxx Opcode | xxxxxxxxxxxxxxxxxxxxxxxxxxxx Fift syntax | xxxxxxxxxxxxxxxxx Stack | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Description | xxxx Gas |
---|---|---|---|---|
B8 | SGN | x - sgn(x) | Computes the sign of an integer x :-1 if x<0 , 0 if x=0 , 1 if x>0 . | 18 |
B9 | LESS | x y - x<y | Returns -1 if x<y , 0 otherwise. | 18 |
BA | EQUAL | x y - x=y | Returns -1 if x=y , 0 otherwise. | 18 |
BB | LEQ | x y - x<=y | 18 | |
BC | GREATER | x y - x>y | 18 | |
BD | NEQ | x y - x!=y | Equivalent to EQUAL NOT . | 18 |
BE | GEQ | x y - x>=y | Equivalent to LESS NOT . | 18 |
BF | CMP | x 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] EQINT | x - x=yy | Returns -1 if x=yy , 0 otherwise.-2^7 <= yy < 2^7 . | 26 |
C000 | ISZERO | x - x=0 | Checks whether an integer is zero. Corresponds to Forth's 0= . | 26 |
C1yy | [yy] LESSINT [yy-1] LEQINT | x - x<yy | Returns -1 if x<yy , 0 otherwise.-2^7 <= yy < 2^7 . | 26 |
C100 | ISNEG | x - x<0 | Checks whether an integer is negative. Corresponds to Forth's 0< . | 26 |
C101 | ISNPOS | x - x<=0 | Checks whether an integer is non-positive. | 26 |
C2yy | [yy] GTINT [yy+1] GEQINT | x - x>yy | Returns -1 if x>yy , 0 otherwise.-2^7 <= yy < 2^7 . | 26 |
C200 | ISPOS | x - x>0 | Checks whether an integer is positive. Corresponds to Forth's 0> . | 26 |
C2FF | ISNNEG | x - x >=0 | Checks whether an integer is non-negative. | 26 |
C3yy | [yy] NEQINT | x - x!=yy | Returns -1 if x!=yy , 0 otherwise.-2^7 <= yy < 2^7 . | 26 |
C4 | ISNAN | x - x=NaN | Checks whether x is a NaN . | 18 |
C5 | CHKNAN | x - x | Throws 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 |
---|---|---|---|---|
C700 | SEMPTY | s - ? | Checks whether a Slice s is empty (i.e., contains no bits of data and no cell references). | 26 |
C701 | SDEMPTY | s - ? | Checks whether Slice s has no bits of data. | 26 |
C702 | SREMPTY | s - ? | Checks whether Slice s has no references. | 26 |
C703 | SDFIRST | s - ? | Checks whether the first bit of Slice s is a one. | 26 |
C704 | SDLEXCMP | s s' - x | Compares the data of s lexicographically with the data of s' , returning -1 , 0, or 1 depending on the result. | 26 |
C705 | SDEQ | s s' - ? | Checks whether the data parts of s and s' coincide, equivalent to SDLEXCMP ISZERO . | 26 |
C708 | SDPFX | s s' - ? | Checks whether s is a prefix of s' . | 26 |
C709 | SDPFXREV | s s' - ? | Checks whether s' is a prefix of s , equivalent to SWAP SDPFX . | 26 |
C70A | SDPPFX | s s' - ? | Checks whether s is a proper prefix of s' (i.e., a prefix distinct from s' ). | 26 |
C70B | SDPPFXREV | s s' - ? | Checks whether s' is a proper prefix of s . | 26 |
C70C | SDSFX | s s' - ? | Checks whether s is a suffix of s' . | 26 |
C70D | SDSFXREV | s s' - ? | Checks whether s' is a suffix of s . | 26 |
C70E | SDPSFX | s s' - ? | Checks whether s is a proper suffix of s' . | 26 |
C70F | SDPSFXREV | s s' - ? | Checks whether s' is a proper suffix of s . | 26 |
C710 | SDCNTLEAD0 | s - n | Returns the number of leading zeroes in s . | 26 |
C711 | SDCNTLEAD1 | s - n | Returns the number of leading ones in s . | 26 |
C712 | SDCNTTRAIL0 | s - n | Returns the number of trailing zeroes in s . | 26 |
C713 | SDCNTTRAIL1 | s - n | Returns the number of trailing ones in s . | 26 |