Skip to content

Commit 5efa98e

Browse files
authored
Use em_math.h functions in jsmath.c (#23147)
Unlike the current EM_JS implementations, the `em_math.h` functions map directly to `Math.xxx` without a wrapper function. The other advantage of doing it this way is that we avoid duplicate implementations of all these functions. Fixes: #19284
1 parent 53c8132 commit 5efa98e

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

system/lib/jsmath.c

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,37 @@
22
// See JS_MATH setting in settings.js for details.
33
//
44

5-
#include <emscripten.h>
5+
#include <emscripten/em_math.h>
6+
#include <emscripten/em_js.h>
67
#include <math.h>
78
#include <stdlib.h>
89

910
#define CALL_JS_1(cname, jsname, type) \
10-
EM_JS(type, JS_##cname, (type x), { return jsname(x) }); \
11-
type cname(type x) { return JS_##cname(x); }
12-
13-
#define CALL_JS_1_TRIPLE(cname, jsname) \
14-
CALL_JS_1(cname, jsname, double) \
15-
CALL_JS_1(cname##f, jsname, float)
16-
17-
CALL_JS_1_TRIPLE(cos, Math.cos)
18-
CALL_JS_1_TRIPLE(sin, Math.sin)
19-
CALL_JS_1_TRIPLE(tan, Math.tan)
20-
CALL_JS_1_TRIPLE(acos, Math.acos)
21-
CALL_JS_1_TRIPLE(asin, Math.asin)
22-
CALL_JS_1_TRIPLE(atan, Math.atan)
23-
CALL_JS_1_TRIPLE(exp, Math.exp)
24-
CALL_JS_1_TRIPLE(log, Math.log)
25-
CALL_JS_1_TRIPLE(sqrt, Math.sqrt)
11+
type cname(type x) { return (type)emscripten_math_##jsname(x); }
12+
13+
#define CALL_JS_1_TRIPLE(name) \
14+
CALL_JS_1(name, name, double) \
15+
CALL_JS_1(name##f, name, float)
16+
17+
CALL_JS_1_TRIPLE(cos)
18+
CALL_JS_1_TRIPLE(sin)
19+
CALL_JS_1_TRIPLE(tan)
20+
CALL_JS_1_TRIPLE(acos)
21+
CALL_JS_1_TRIPLE(asin)
22+
CALL_JS_1_TRIPLE(atan)
23+
CALL_JS_1_TRIPLE(exp)
24+
CALL_JS_1_TRIPLE(log)
25+
CALL_JS_1_TRIPLE(sqrt)
2626

2727
#define CALL_JS_2(cname, jsname, type) \
28-
EM_JS(type, JS_##cname, (type x, type y), { return jsname(x, y) }); \
29-
type cname(type x, type y) { return JS_##cname(x, y); }
28+
type cname(type x, type y) { return (type)emscripten_math_##jsname(x, y); }
3029

31-
#define CALL_JS_2_TRIPLE(cname, jsname) \
32-
CALL_JS_2(cname, jsname, double) \
33-
CALL_JS_2(cname##f, jsname, float)
30+
#define CALL_JS_2_TRIPLE(name) \
31+
CALL_JS_2(name, name, double) \
32+
CALL_JS_2(name##f, name, float)
3433

35-
CALL_JS_2_TRIPLE(atan2, Math.atan2)
36-
CALL_JS_2_TRIPLE(pow, Math.pow)
34+
CALL_JS_2_TRIPLE(atan2)
35+
CALL_JS_2_TRIPLE(pow)
3736

3837
#define CALL_JS_1_IMPL(cname, type, impl) \
3938
EM_JS(type, JS_##cname, (type x), impl); \

0 commit comments

Comments
 (0)