降级
demote 指令用于将 f64 类型数字(双精度浮点数)转换为 f32 类型数字(单精度浮点数)。
试一试
(module
(import "console" "log" (func $log (param f32)))
(func $main
f64.const 10.5 ;; push an f64 onto the stack
f32.demote_f64 ;; demote from f64 to f32
call $log ;; log the result
)
(start $main)
)
const url = "{%wasm-url%}";
await WebAssembly.instantiateStreaming(fetch(url), { console });
语法
wat
;; push an f64 onto the stack
f64.const 10.5
;; demote from f64 to f32
f32.demote_f64
;; the top item on the stack will now be the value 10.5 of type f32
| 指令 | 二进制操作码 |
|---|---|
f32.demote_f64 |
0xb6 |