取反
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 |