-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Remove rint from jsmath library. NFC #23148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,9 +45,3 @@ CALL_JS_2_TRIPLE(pow) | |
| 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); | ||
| } | ||
| return (x - Math.floor(x) != .5) ? round(x) : round(x / 2) * 2; | ||
| }) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, I am not certain the new code is smaller, as unless I am doing something wrong, even though #include <emscripten.h>
int main(int argc, char **argv) {
double x = double(argc + 1000) / double(argc + 100);
return __builtin_rint(x);
}
(func $main (param $0 i32) (param $1 i32) (result i32)
(local $2 f64)
(if
(f64.lt
(f64.abs
(local.tee $2
(f64.nearest
(f64.div
(f64.convert_i32_s
(i32.add
(local.get $0)
(i32.const 1000)
)
)
(f64.convert_i32_s
(i32.add
(local.get $0)
(i32.const 100)
)
)
)
)
)
)
(f64.const 2147483648)
)
(then
(return
(i32.trunc_f64_s
(local.get $2)
)
)
)
)
(i32.const -2147483648)
)Ignoring the division etc., it looks like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The rest of the complixity in your example I think comes from the conversion from double to int because your are returning and double from your main function. If I do this I see the expected results: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, you're right, I missed the other conversion, sorry... |
||
Uh oh!
There was an error while loading. Please reload this page.