Back to Content

WebAssembly numeric instructions

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

latest4.3 KB
Original Source

WebAssembly numeric instructions.

Constants

  • const
    • : Declare a constant numbers.

Comparison

  • eq
    • : Check if two numbers are equal.
  • ne
    • : Check if two numbers are not equal.
  • gt
    • : Check if a number is greater than another number.
  • lt
    • : Check if a number is less than another number.
  • ge
    • : Check if a number is greater than or equal to another number.
  • le
    • : Check if a number is less than or equal to another number.

Arithmetic

  • add
    • : Add up two numbers.
  • sub
    • : Subtract one number from another number.
  • mul
    • : Multiply one number by another number.
  • div
    • : Divide one number by another number.
  • rem
    • : Calculate the remainder left over when one integer is divided by another integer.

Conversion

  • extend
    • : Convert (extend) i32 to i64.
  • wrap
    • : Convert (wrap) i64 to i32.
  • promote
    • : Convert (promote) f32 to f64.
  • demote
    • : Convert (demote) f64 to f32.
  • convert
    • : Convert integers to floating points.
  • trunc (to int)
    • : Convert (truncate fractional part) floating points to integers.
  • reinterpret
    • : Reinterpret the bytes of integers as floating points and vice versa.

Floating point specific instructions

  • min
    • : Get the lower of two numbers.
  • max
    • : Get the higher of two numbers.
  • nearest
    • : Round a number to the nearest integer.
  • ceil
    • : Round up a number.
  • floor
    • : Round down a number.
  • trunc (to float)
    • : Discard the fractional part of a number.
  • abs
    • : Get the absolute value of a number.
  • neg
    • : Negate a number.
  • sqrt
    • : Get the square root of a number.
  • copysign
    • : Copy just the sign bit from one number to another.

Bitwise

  • and
    • : Used for performing a bitwise AND.
  • or
    • : Used for performing a bitwise OR.
  • xor
    • : Used for performing a bitwise XOR.
  • shl
    • : Used for performing a bitwise left-shift.
  • shr
    • : Used for performing a bitwise right-shift.
  • rotl
    • : Used for performing a bitwise left-rotate.
  • rotr
    • : Used for performing a bitwise right-rotate.
  • clz
    • : Count the amount of leading zeros in a numbers binary representation.
  • ctz
    • : Count the amount of trailing zeros in a numbers binary representation.
  • popcnt
    • : Count the total amount of 1s in a numbers binary representation.