Comparisons in WebAssembly
Tests return an i32 — one for true, zero for false.
(module
;; Comparisons return i32: one for true, zero for false. The _s and
;; _u suffixes say how to read the sign bit.
(func (export "is_freezing") (param $temp i32) (result i32)
(i32.le_s (local.get $temp) (i32.const 0)))
(func (export "in_range") (param $n i32) (param $lo i32) (param $hi i32)
(result i32)
(i32.and
(i32.ge_s (local.get $n) (local.get $lo))
(i32.le_s (local.get $n) (local.get $hi))))
;; eqz is the one-operand shortcut for "equals zero".
(func (export "is_empty") (param $count i32) (result i32)
(i32.eqz (local.get $count))))
How it works
i32.le_scompares signed; the result is just an integer.i32.andcombines two tests into a range check.i32.eqzis the shorthand for comparing against zero.
Keywords and builtins used here
exportfunci32moduleparamresult
The run, in numbers
- Lines
- 15
- Characters to type
- 550
- Tokens
- 113
- Three-star pace
- 65 tpm
At the three-star pace of 65 tokens a minute, this run takes about 104 seconds.
Step 2 of 3 in Numbers, step 5 of 28 in Language basics.