Skip to content

Commit

Permalink
Add more math bindings for Wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
luboslenco committed Jan 16, 2023
1 parent d04a7e6 commit 94c8f89
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Backends/System/Wasm/JS-Sources/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,17 @@ async function init() {
js_cos: function(x) {
return Math.cos(x);
},
js_tan: function(x) {
return Math.tan(x);
},
js_log: function(base, exponent) {
return Math.log(base, exponent);
},
js_exp: function(x) {
return Math.exp(x);
},
js_sqrt: function(x) {
return Math.sqrt(x);
}
}
}
Expand Down
23 changes: 23 additions & 0 deletions miniClib/math.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ __attribute__((import_module("imports"), import_name("js_pow"))) float js_pow(fl
__attribute__((import_module("imports"), import_name("js_floor"))) float js_floor(float x);
__attribute__((import_module("imports"), import_name("js_sin"))) float js_sin(float x);
__attribute__((import_module("imports"), import_name("js_cos"))) float js_cos(float x);
__attribute__((import_module("imports"), import_name("js_tan"))) float js_tan(float x);
__attribute__((import_module("imports"), import_name("js_log"))) float js_log(float x);
__attribute__((import_module("imports"), import_name("js_exp"))) float js_exp(float x);
__attribute__((import_module("imports"), import_name("js_sqrt"))) float js_sqrt(float x);
#endif

double ldexp(double x, int exp) {
Expand Down Expand Up @@ -62,6 +64,20 @@ float cosf(float x) {
return 0.0f;
}

double tan(double x) {
#ifdef KORE_WASM
return js_tan(x);
#endif
return 0.0;
}

float tanf(float x) {
#ifdef KORE_WASM
return js_tan(x);
#endif
return 0.0f;
}

double log(double x) {
#ifdef KORE_WASM
return js_log(x);
Expand All @@ -75,3 +91,10 @@ double exp(double x) {
#endif
return 0.0;
}

double sqrt(double x) {
#ifdef KORE_WASM
return js_sqrt(x);
#endif
return 0.0;
}
6 changes: 6 additions & 0 deletions miniClib/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@ double cos(double x);

float cosf(float x);

double tan(double x);

float tanf(float x);

double log(double x);

double exp(double x);

double sqrt(double x);

#ifdef __cplusplus
}
#endif

0 comments on commit 94c8f89

Please sign in to comment.