diff options
| author | bors <bors@rust-lang.org> | 2025-06-09 21:21:58 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-06-09 21:21:58 +0000 |
| commit | c6768de2d63de7a41124a0fb8fc78f9e26111c01 (patch) | |
| tree | 0353ff7cc2d97021a526887a4be635d48a0eab5c /library/std/src/num/f64.rs | |
| parent | d13a431a6cc69cd65efe7c3eb7808251d6fd7a46 (diff) | |
| parent | 00452bd783a2c91b85cfb37e650628674c64b006 (diff) | |
| download | rust-c6768de2d63de7a41124a0fb8fc78f9e26111c01.tar.gz rust-c6768de2d63de7a41124a0fb8fc78f9e26111c01.zip | |
Auto merge of #138062 - LorrensP-2158466:miri-enable-float-nondet, r=RalfJung
Enable Non-determinism of float operations in Miri and change std tests Links to [#4208](https://github.com/rust-lang/miri/issues/4208) and [#3555](https://github.com/rust-lang/miri/issues/3555) in Miri. Non-determinism of floating point operations was disabled in rust-lang/rust#137594 because it breaks the tests and doc-tests in core/coretests and std. This PR enables some of them. This pr includes the following changes: - Enables the float non-determinism but with a lower relative error of 4ULP instead of 16ULP - These operations now have a fixed output based on the C23 standard, except the pow operations, this is tracked in [#4286](https://github.com/rust-lang/miri/issues/4286#issue-3010677983) - Changes tests that made incorrect assumptions about the operations, not to make that assumption anymore (from `assert_eq!` to `assert_approx_eq!`. - Changed the doctests of the stdlib of these operations to compare against fixed constants instead of `f*::EPSILON`, which now succeed with Miri and `-Zmiri-many-seeds` - Added a constant `APPROX_DELTA` in `std/tests/floats/f32.rs` which is used for approximation tests, but with a different value when run in Miri. This is to make these tests succeed. - Added tests in the float tests of Miri to test the C23 behaviour. Fixes https://github.com/rust-lang/miri/issues/4208
Diffstat (limited to 'library/std/src/num/f64.rs')
| -rw-r--r-- | library/std/src/num/f64.rs | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/library/std/src/num/f64.rs b/library/std/src/num/f64.rs index 75e35a8db33..853417825f9 100644 --- a/library/std/src/num/f64.rs +++ b/library/std/src/num/f64.rs @@ -304,7 +304,7 @@ impl f64 { /// ``` /// let x = 2.0_f64; /// let abs_difference = (x.powi(2) - (x * x)).abs(); - /// assert!(abs_difference <= f64::EPSILON); + /// assert!(abs_difference <= 1e-14); /// /// assert_eq!(f64::powi(f64::NAN, 0), 1.0); /// ``` @@ -328,7 +328,7 @@ impl f64 { /// ``` /// let x = 2.0_f64; /// let abs_difference = (x.powf(2.0) - (x * x)).abs(); - /// assert!(abs_difference <= f64::EPSILON); + /// assert!(abs_difference <= 1e-14); /// /// assert_eq!(f64::powf(1.0, f64::NAN), 1.0); /// assert_eq!(f64::powf(f64::NAN, 0.0), 1.0); @@ -754,7 +754,7 @@ impl f64 { /// // asin(sin(pi/2)) /// let abs_difference = (f.sin().asin() - std::f64::consts::FRAC_PI_2).abs(); /// - /// assert!(abs_difference < 1e-10); + /// assert!(abs_difference < 1e-7); /// ``` #[doc(alias = "arcsin")] #[rustc_allow_incoherent_impl] |
