-
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
Fix issue of missing sign in binary_float_op when result of rem is zero #109573
Fix issue of missing sign in binary_float_op when result of rem is zero #109573
Conversation
r? @wesleywiser (rustbot has picked a reviewer for you, use r? to override) |
Some changes occurred to the CTFE / Miri engine cc @rust-lang/miri |
Rem => { | ||
let v = (l % r).value; | ||
// IEEE754 requires this | ||
let r = if v.is_zero() { v.copy_sign(l) } else { v }; | ||
(r.into(), ty) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is the proper place to fix this. l % r
should already give you the right result. There is likely something wrong in the rustc_apfloat
crate, probably here, though I don't really understand how soft float works
rust/compiler/rustc_apfloat/src/ieee.rs
Lines 1003 to 1017 in f421586
(Category::Normal, Category::Normal) => { | |
while self.is_finite_non_zero() | |
&& rhs.is_finite_non_zero() | |
&& self.cmp_abs_normal(rhs) != Ordering::Less | |
{ | |
let mut v = rhs.scalbn(self.ilogb() - rhs.ilogb()); | |
if self.cmp_abs_normal(v) == Ordering::Less { | |
v = v.scalbn(-1); | |
} | |
v.sign = self.sign; | |
let status; | |
self = unpack!(status=, self - v); | |
assert_eq!(status, Status::OK); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, you're right, I didn't notice use rustc_apfloat::Float
.
I think we may have a similar fix at here? I updated the code.
tests/ui/mir/issue-109567.rs
Outdated
// check-run-results | ||
|
||
pub fn f() -> f64 { | ||
std::hint::black_box(-1.0) % std::hint::black_box(-1.0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What part of the compiler are you specifically trying to test here?
If you're updating const eval, maybe it would make sense to add a test for this in https://github.com/rust-lang/rust/tree/master/tests/mir-opt/const_prop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new fix don't change mir
part, so I moved the test case to tests/ui/numbers-arithmetic/
.
345cdba
to
965a05d
Compare
1336670
to
dacbb8d
Compare
dacbb8d
to
99f7fb0
Compare
std::hint::black_box(-1.0) % std::hint::black_box(-1.0) | ||
} | ||
|
||
pub fn g() -> f64 { | ||
const fn g() -> f64 { | ||
-1.0 % -1.0 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does nothing. Making a const fn
just means the function can be called from a const
, but you are not doing that, and then it is a total NOP.
What I meant is something like
const G: f64 = -1.0 % -1.0;
Then you also don't need the feature gate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed it.
According to #109573 (comment), it's not suggested to make changes to this file? 🤔
abd8a4d
to
eb59b9c
Compare
Yeah, Rust's apfloat port has been in licensing limbo for years, meaning we have no idea how to even go about fixing bugs in it. :( |
If we can't change apfloat, I suggest that @chenyukang revert to the original patch of doing the check in |
Not sure I agree -- littering the surrounding code with checks to patch the results sounds pretty bad. FWIW this is not the only bugfix that is blocked on apfloat. We really need to figure out the apfloat situations, and solve it properly. |
seems we are blocking at this PR: #96784 |
I posted a longer update to #55993 (comment) regarding the progress with the whole |
Hi @chenyukang, thanks for the fix! As @eddyb mentioned, this has been fixed in the new version of the Thanks again for your efforts! 🙂 |
Fixes #109567