取反
neg
指令,即 negate(取反)的缩写,用于对数字取反。也就是说,将正数变成负数,将负数变成正数。
试一试
(module
(import "console" "log" (func $log (param f32)))
(func $main
f32.const 10 ;; load a number onto the stack
f32.neg ;; negate the values
call $log ;; log the result
)
(start $main)
)
const url = "{%wasm-url%}";
await WebAssembly.instantiateStreaming(fetch(url), { console });
语法
wat
;; load a number onto the stack
f32.const 2.7
;; negate
f32.neg
;; the top item on the stack will now be -2.7
指令 | 二进制操作码 |
---|---|
f32.neg |
0x8c |
f64.neg |
0x9a |