Skip to content

Commit 8667034

Browse files
committed
fix applying an error to infinities
1 parent 18683c2 commit 8667034

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/tools/miri/src/math.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ pub(crate) fn apply_random_float_error<F: rustc_apfloat::Float>(
1515
|| matches!(ecx.machine.float_rounding_error, FloatRoundingErrorMode::None)
1616
// relative errors don't do anything to zeros... avoid messing up the sign
1717
|| val.is_zero()
18+
// The logic below makes no sense if the input is already non-finite.
19+
|| !val.is_finite()
1820
{
1921
return val;
2022
}
@@ -54,6 +56,8 @@ pub(crate) fn apply_random_float_error_ulp<F: rustc_apfloat::Float>(
5456
// FIXME: also disturb zeros? That requires a lot more cases in `fixed_float_value`
5557
// and might make the std test suite quite unhappy.
5658
|| val.is_zero()
59+
// The logic below makes no sense if the input is already non-finite.
60+
|| !val.is_finite()
5761
{
5862
return val;
5963
}

src/tools/miri/tests/pass/float.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,10 @@ pub fn libm() {
10521052
assert_eq!(42f64.powf(0.0), 1.0);
10531053
assert_eq!(f32::INFINITY.powf(0.0), 1.0);
10541054
assert_eq!(f64::INFINITY.powf(0.0), 1.0);
1055+
assert_eq!(f32::NEG_INFINITY.powi(3), f32::NEG_INFINITY);
1056+
assert_eq!(f32::NEG_INFINITY.powi(2), f32::INFINITY);
1057+
assert_eq!(f64::INFINITY.powi(3), f64::INFINITY);
1058+
assert_eq!(f64::INFINITY.powi(2), f64::INFINITY);
10551059

10561060
// f*::NAN is a quiet NAN and should return 1 as well.
10571061
assert_eq!(f32::NAN.powi(0), 1.0);

0 commit comments

Comments
 (0)