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

Map

Takes x and scales it from one range to another range.

(module
  (func (export "map") (param $v f32) (param $min1 f32) (param $max1 f32) (param $min2 f32) (param $max2 f32) (result f32)

    (f32.add 
      (get_local $min2)
      (f32.div 
        (f32.mul 
          (f32.sub (get_local $v) (get_local $min1))
          (f32.sub (get_local $max2) (get_local $min1))
        )
         (f32.sub (get_local $max1) (get_local $min1))
      )
    )
  )
)
PreviousDistNextFract

Last updated 5 years ago

Was this helpful?