Back to Content

demote: Wasm text instruction

files/en-us/webassembly/reference/numeric/demote/index.md

latest828 B
Original Source

The demote instructions are used to convert (demote) numbers of type f64 to type f32.

{{InteractiveExample("Wat Demo: demote", "tabbed-taller")}}

wat
(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)
)
js
const url = "{%wasm-url%}";
await WebAssembly.instantiateStreaming(fetch(url), { console });

Syntax

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
InstructionBinary opcode
f32.demote_f640xb6