Skip to content

Commit

Permalink
Remove unnecessary functions from JSMATH. NFC
Browse files Browse the repository at this point in the history
See the comments at the top of `emscripten/js_math.h` for why JS
versions of these functions are not needed.

As a followup I plan to map `jsmath.c` functions to `em_math.h`
functions instead of using EM_JS here.

See #19284
  • Loading branch information
sbc100 committed Dec 12, 2024
1 parent 1171ada commit 1c9b29d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 10 deletions.
2 changes: 1 addition & 1 deletion system/include/emscripten/em_math.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ extern "C" {
// Math.ceil -> f32.ceil and f64.ceil (ceil() and ceilf() in math.h)
// Math.clz32(x) -> i32.clz and i64.clz (call __builtin_clz() and __builtin_clzll())
// Math.floor -> f32.floor and f64.floor (floor() and floorf() in math.h)
// Math.fround -> f64.promote_f32(f32.demote_f64()) (call double d = (double)(float)someDouble;)
// Math.fround -> f64.promote_f32(f32.demote_f64()) (double d = (double)(float)someDouble;)
// Math.imul(x, y) -> i32.mul and i64.mul (directly multiply two signed integers)
// Math.min -> f32.min and f64.min (fminf() and fmin() in math.h)
// Math.max -> f32.max and f64.max (fmaxf() and fmax() in math.h)
Expand Down
10 changes: 1 addition & 9 deletions system/lib/jsmath.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ CALL_JS_1_TRIPLE(atan, Math.atan)
CALL_JS_1_TRIPLE(exp, Math.exp)
CALL_JS_1_TRIPLE(log, Math.log)
CALL_JS_1_TRIPLE(sqrt, Math.sqrt)
CALL_JS_1_TRIPLE(fabs, Math.abs)
CALL_JS_1_TRIPLE(ceil, Math.ceil)
CALL_JS_1_TRIPLE(floor, Math.floor)

#define CALL_JS_2(cname, jsname, type, casttype) \
EM_JS(type, JS_##cname, (type x, type y), { return jsname(x, y) }); \
Expand All @@ -50,11 +47,6 @@ CALL_JS_1_IMPL_TRIPLE(round, {
return x >= 0 ? Math.floor(x + 0.5) : Math.ceil(x - 0.5);
})
CALL_JS_1_IMPL_TRIPLE(rint, {
function round(x) {
return x >= 0 ? Math.floor(x + 0.5) : Math.ceil(x - 0.5);
}
var round(x) => x >= 0 ? Math.floor(x + 0.5) : Math.ceil(x - 0.5);
return (x - Math.floor(x) != .5) ? round(x) : round(x / 2) * 2;
})

double nearbyint(double x) { return rint(x); }
float nearbyintf(float x) { return rintf(x); }

0 comments on commit 1c9b29d

Please sign in to comment.