MDN / convert: Wasm numeric instruction
MDN / convert: Wasm numeric instruction
The convert numeric instructions are used for converting integer numbers to floating point numbers. There are signed and unsigned versions of this instruction.
(module
(import "console" "log" (func $log (param f32)))
(func $main
i32.const 10 ;; push an i32 onto the stack
f32.convert_i32_s ;; convert from signed i32 to f32
call $log ;; log the result
)
(start $main)
)
const url = "{%wasm-url%}";
await WebAssembly.instantiateStreaming(fetch(url), { console });
Syntax
;; push an i32 onto the stack
i32.const 10
;; convert from signed i32 to f32
f32.convert_i32_s
;; the top item on the stack will now be the value 10 of type f32
InstructionBinary opcodef32.convert_i32_s0xb2f32.convert_i32_u0xb3f32.convert_i64_s0xb4f32.convert_i64_u0xb5f64.convert_i32_s0xb7f64.convert_i32_u0xb8f64.convert_i64_s0xb9f64.convert_i64_u0xba