Wasm Reference
  • Welcome
  • Nodejs WAT Compiler
  • Types
    • Functions
    • Globals
    • Linear Memory
    • Tables
    • Numbers
    • Text
  • Structures
    • IF
    • LOOP
  • Algorithms
    • Hello World
    • Estimate Pi
  • Maths Helper Algorithms
    • Pseudorandom Number Generator
    • Factorial
    • Dist
    • Map
    • Fract
    • RemF or ModF
    • Round
    • Clamp
    • Mix
    • Pow
    • Approx Sin
    • Approx Cos
    • Approx Tan
    • ToRad and ToDeg
Powered by GitBook
On this page

Was this helpful?

  1. Maths Helper Algorithms

RemF or ModF

Gets the modulus of a f32

(module 
  (func $fract (export "fract") (param $x f32) (result f32)
    (f32.sub
      (get_local $x)
      (f32.floor (get_local $x))
    )
  )
  (func $remf (export "remf") (param $x f32)  (param $y f32) (result f32)
    (f32.div
      (get_local $x)
      (get_local $y)
    )
    call $fract
    (get_local $y)
    f32.mul
  )
)
PreviousFractNextRound

Last updated 5 years ago

Was this helpful?