File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change 1+ (module
2+
3+ ;; #include <math.h>
4+ ;;
5+ ;; double distance(double x1, double y1, double x2, double y2) {
6+ ;; double a = x1 - x2;
7+ ;; double b = y1 - y2;
8+ ;; return sqrt(pow(a, 2) + pow(b, 2));
9+ ;; }
10+ (func $distance (param $x1 f64 ) (param $y1 f64 ) (param $x2 f64 ) (param $y2 f64 ) (result f64 )
11+ (f64.sqrt
12+ (f64.add
13+ (f64.mul
14+ (tee_local $x1
15+ (f64.sub
16+ (get_local $x1 )
17+ (get_local $x2 )))
18+ (get_local $x1 ))
19+ (f64.mul
20+ (tee_local $x1
21+ (f64.sub
22+ (get_local $y1 )
23+ (get_local $y2 )))
24+ (get_local $x1 )))))
25+
26+
27+ ;; in a different way
28+ (func $distance2 (param $x1 f64 ) (param $y1 f64 ) (param $x2 f64 ) (param $y2 f64 ) (result f64 )
29+ (f64.sqrt
30+ (f64.add
31+ (call $square
32+ (f64.sub
33+ (get_local $x1 )
34+ (get_local $x2 )))
35+ (call $square
36+ (f64.sub
37+ (get_local $y1 )
38+ (get_local $y2 ))))))
39+
40+ (func $square (param $a f64 ) (result f64 )
41+ (f64.mul
42+ (get_local $a )
43+ (get_local $a )))
44+ )
You can’t perform that action at this time.
0 commit comments