Skip to content
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

Double::op_mod on Wasm backend produce JS-inconsistent result when the divisor is in subnormal range #1303

Closed
tonyfettes opened this issue Dec 6, 2024 · 3 comments · Fixed by #1367
Assignees

Comments

@tonyfettes
Copy link
Contributor

tonyfettes commented Dec 6, 2024

Expression Js Wasm
5e-324 % 5e-324 0 -2.1219957905e-314
0.5 % 1.5e-323 1e-323 -3.5837322939398236e-299
@tonyfettes tonyfettes changed the title Double::op_mod produce inconsistency result when the divisor is in subnormal range Double::op_mod on Wasm{,GC} backend produce JS-inconsistent result when the divisor is in subnormal range Dec 6, 2024
@Lampese Lampese self-assigned this Dec 6, 2024
@tonyfettes tonyfettes changed the title Double::op_mod on Wasm{,GC} backend produce JS-inconsistent result when the divisor is in subnormal range Double::op_mod on Wasm backend produce JS-inconsistent result when the divisor is in subnormal range Dec 6, 2024
@Lampese
Copy link
Collaborator

Lampese commented Dec 9, 2024

Actually, this error is acceptable for numerical algorithms... but for platformity, algorithms do need to be unified, and the priority may not be as high?
cc @tonyfettes

@liuly0322
Copy link
Contributor

Hi everyone, I have just verified (from the discussion) that rust-wasm is using libm to standardize their math intrinsics, and their implementation is right (5e-324 % 5e-324 == 0), so the inconsistency is from the current MoonBit fmod implementation for non-js platforms.

IMO it's a bit more than just platformity, as many programming languages are using libm as their math library. We can refer to the libm to check the implementation of other math intrinsics too.

I'm going to open a PR to fix the current fmod algorithm soon, Thanks.

@tonyfettes
Copy link
Contributor Author

@liuly0322 Sounds good, make sure to update NOTICE to include license from libm (and possibly from musl) as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants