Skip to content

Commit

Permalink
Fix issue of binary_float_op when result of rem is zero
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyukang committed Mar 25, 2023
1 parent c90eb48 commit 99f7fb0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
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
16 changes: 16 additions & 0 deletions tests/ui/numbers-arithmetic/issue-109567.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// run-pass
// check-run-results

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

pub fn g() -> f64 {
-1.0 % -1.0
}

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

0 comments on commit 99f7fb0

Please sign in to comment.