about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2025-09-03 21:22:43 +0200
committerRalf Jung <post@ralfj.de>2025-09-03 21:22:43 +0200
commit86670347189962f15061404526acab2a6bb0da8f (patch)
tree57a0da07aec497f64c119155eab8fa907f1d55ef /src
parent18683c20aec00908d06255f9688cc1efb6eff10c (diff)
downloadrust-86670347189962f15061404526acab2a6bb0da8f.tar.gz
rust-86670347189962f15061404526acab2a6bb0da8f.zip
fix applying an error to infinities
Diffstat (limited to 'src')
-rw-r--r--src/tools/miri/src/math.rs4
-rw-r--r--src/tools/miri/tests/pass/float.rs4
2 files changed, 8 insertions, 0 deletions
diff --git a/src/tools/miri/src/math.rs b/src/tools/miri/src/math.rs
index 604d6c0fd73..6427f3ca6e9 100644
--- a/src/tools/miri/src/math.rs
+++ b/src/tools/miri/src/math.rs
@@ -15,6 +15,8 @@ pub(crate) fn apply_random_float_error<F: rustc_apfloat::Float>(
         || matches!(ecx.machine.float_rounding_error, FloatRoundingErrorMode::None)
         // relative errors don't do anything to zeros... avoid messing up the sign
         || val.is_zero()
+        // The logic below makes no sense if the input is already non-finite.
+        || !val.is_finite()
     {
         return val;
     }
@@ -54,6 +56,8 @@ pub(crate) fn apply_random_float_error_ulp<F: rustc_apfloat::Float>(
         // FIXME: also disturb zeros? That requires a lot more cases in `fixed_float_value`
         // and might make the std test suite quite unhappy.
         || val.is_zero()
+        // The logic below makes no sense if the input is already non-finite.
+        || !val.is_finite()
     {
         return val;
     }
diff --git a/src/tools/miri/tests/pass/float.rs b/src/tools/miri/tests/pass/float.rs
index 2be262d76a4..1b1163c7797 100644
--- a/src/tools/miri/tests/pass/float.rs
+++ b/src/tools/miri/tests/pass/float.rs
@@ -1052,6 +1052,10 @@ pub fn libm() {
     assert_eq!(42f64.powf(0.0), 1.0);
     assert_eq!(f32::INFINITY.powf(0.0), 1.0);
     assert_eq!(f64::INFINITY.powf(0.0), 1.0);
+    assert_eq!(f32::NEG_INFINITY.powi(3), f32::NEG_INFINITY);
+    assert_eq!(f32::NEG_INFINITY.powi(2), f32::INFINITY);
+    assert_eq!(f64::INFINITY.powi(3), f64::INFINITY);
+    assert_eq!(f64::INFINITY.powi(2), f64::INFINITY);
 
     // f*::NAN is a quiet NAN and should return 1 as well.
     assert_eq!(f32::NAN.powi(0), 1.0);