trunc_f64_s: Wasm-Textinstruktion
Die trunc_f64_s-Instruktion entfernt den Bruchteil eines f64-Wertes und gibt ihn als vorzeichenbehaftete Ganzzahl aus.
Dies ist eine separate Instruktion, trunc, die den Bruchteil einer Gleitkommazahl entfernt und eine Gleitkommazahl ausgibt.
Es gibt auch andere Instruktionen zur Konvertierung mit Trunkierung von Ganzzahlen:
Probieren Sie es aus
(module
(import "console" "log" (func $log (param i32)))
(func $main
f64.const 2300044.4 ;; load a number onto the stack
i32.trunc_f64_s ;; discard decimal part and return signed integer
call $log ;; log the result
)
(start $main)
)
const url = "{%wasm-url%}";
await WebAssembly.instantiateStreaming(fetch(url), { console });
Syntax
value_type.trunc_f64_s
value_type-
Der Typ des Wertes, auf den die Instruktion angewendet wird. Die folgenden Typen unterstützen
trunc_f64_s:i32i64
trunc_f64_s-
Die
trunc_f64_s-Instruktion. Muss immer nach demvalue_typeund einem Punkt (.) angegeben werden.
Typ
[input] -> [output]
Binärcodierung
| Instruktion | Binärformat | Beispieltext => binär |
|---|---|---|
i32.trunc_f64_s |
0xaa |
i32.trunc_f64_s => 0xaa |
i64.trunc_f64_s |
0xb0 |
i64.trunc_f64_s => 0xb0 |