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

Fix issue of missing sign in binary_float_op when result of rem is zero #109573

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions compiler/rustc_apfloat/src/ieee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,7 @@ impl<S: Semantics> Float for IeeeFloat<S> {
(Category::Infinity, _) | (_, Category::Zero) => Status::INVALID_OP.and(Self::NAN),

(Category::Normal, Category::Normal) => {
let sign = self.sign;
while self.is_finite_non_zero()
&& rhs.is_finite_non_zero()
&& self.cmp_abs_normal(rhs) != Ordering::Less
Expand All @@ -1015,6 +1016,10 @@ impl<S: Semantics> Float for IeeeFloat<S> {
self = unpack!(status=, self - v);
assert_eq!(status, Status::OK);
}
// IEEE754 requires this
if self.is_zero() {
self.sign = sign;
}
Status::OK.and(self)
}
}
Expand Down
14 changes: 14 additions & 0 deletions tests/ui/numbers-arithmetic/issue-109567.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// run-pass
// check-run-results

fn f() -> f64 {
std::hint::black_box(-1.0) % std::hint::black_box(-1.0)
}

const G: f64 = -1.0 % -1.0;

pub fn main() {
assert_eq!(-1, G.signum() as i32);
assert_eq!((-0.0_f64).to_bits(), G.to_bits());
assert_eq!(f().signum(), G.signum());
}