MDN / trunc_f32_u: Wasm numeric instruction
MDN / trunc_f32_u: Wasm numeric instruction
The trunc_f32_u numeric instruction removes the fractional part of an f32 value and outputs it as an unsigned integer.
This is a separate instruction, trunc, which removes the fractional part of a float and outputs a float.
There are also other truncate integer conversion instructions:
(module
(import "console" "log" (func $log (param i32)))
(func $main
f32.const 2344.8 ;; load a number onto the stack
i32.trunc_f32_u ;; discard decimal part and return unsigned integer
call $log ;; log the result
)
(start $main)
)
const url = "{%wasm-url%}";
await WebAssembly.instantiateStreaming(fetch(url), { console });
Syntax
value_type.trunc_f32_u
value_type: The type of value the instruction is being run on. The following types support
trunc_f32_u:i32i64
trunc_f32_u: The
trunc_f32_uinstruction. Must always be included after thevalue_typeand a period (.).
Type
[input] -> [output]
input: The input floating point number.
output: The output integer.
Binary encoding
InstructionBinary formatExample text => binaryi32.trunc_f32_u0xa9i32.trunc_f32_u => 0xa9i64.trunc_f32_u0xafi64.trunc_f32_u => 0xaf