-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Floating point modulo producing incorrect compuations #111405
Comments
Small note: the manual implementation should be The mod impl says that these operations should be equivalent. |
After investigation, the answer given by Rust is congruent to 0.0 within the mod. However, the main concern to me is this behavior breaks the identity given for rem_euclid in the std docs quite badly. The rem_euclid identity given is:
https://doc.rust-lang.org/std/primitive.f32.html#method.rem_euclid Example playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=838ccc4e48cd3ef6fa7c475ba1fae693 Output:
|
Note also that the libc remainderf gives a much better result here, but Rust + LLVM doesn't use this implementation. |
Results on Windows 10 for those curious if there is a difference.
|
Rem Given that definition, I do believe
There's an existing issue about |
I may have a related problem. While working on https://github.com/imsnif/bandwhich/ I noticed that some computed test snapshots are different on Windows. Upon further investigation, it seems like it's due to the dreaded floating point math. Here's a sample: println!("{:?}", 2.5f64.powi(39)); On Linux and MacOS this computes to Tested on 1.70, 1.74, 1.77, and nightly; identical behivour between the versions. |
I tried this code:
I expected the assert to pass.
Instead, this happened:
Meta
This is most likely due to division being rounded, but mod not. This caused a bug in a sin table function I was writing.
This is standard libc behavior but it is still not correct and can cause bugs where none are expected.
rustc --version --verbose
:Backtrace
The text was updated successfully, but these errors were encountered: