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

Dist

Gets the distance between points.

(module
  (func (export "dist") (param $x1 f32) (param $y1 f32) (param $x2 f32) (param $y2 f32) (result f32)
    (local $x0 f32)
    (local $y0 f32)

    (f32.sub (get_local $x1) (get_local $x2))
    set_local $x0
    (f32.sub (get_local $y1) (get_local $y2))
    set_local $y0

    (f32.add
      (f32.mul (get_local $x0) (get_local $x0))
      (f32.mul (get_local $y0) (get_local $y0))
    )

    f32.sqrt
  )
)
PreviousFactorialNextMap

Last updated 5 years ago

Was this helpful?