Back to Content

ceil: Wasm text instruction

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

latest787 B
Original Source

The ceil instructions are used for getting the value of a number rounded up to the next integer.

{{InteractiveExample("Wat Demo: ceil", "tabbed-standard")}}

wat
(module
  (import "console" "log" (func $log (param f32)))
  (func $main

    f32.const 2.7 ;; load a number onto the stack
    f32.ceil ;; round up
    call $log ;; log the result

  )
  (start $main)
)
js
const url = "{%wasm-url%}";
await WebAssembly.instantiateStreaming(fetch(url), { console });

Syntax

wat
;; load a number onto the stack
f32.const 2.7

;; round up
f32.ceil

;; the top item on the stack will now be 3
InstructionBinary opcode
f32.ceil0x8d
f64.ceil0x9b