about summary refs log tree commit diff
path: root/library/coretests/tests
diff options
context:
space:
mode:
Diffstat (limited to 'library/coretests/tests')
-rw-r--r--library/coretests/tests/floats/f32.rs9
-rw-r--r--library/coretests/tests/floats/f64.rs2
-rw-r--r--library/coretests/tests/num/dec2flt/float.rs6
3 files changed, 12 insertions, 5 deletions
diff --git a/library/coretests/tests/floats/f32.rs b/library/coretests/tests/floats/f32.rs
index 4e6509ead2b..98e9695d090 100644
--- a/library/coretests/tests/floats/f32.rs
+++ b/library/coretests/tests/floats/f32.rs
@@ -23,6 +23,11 @@ const NAN_MASK1: u32 = 0x002a_aaaa;
 /// Second pattern over the mantissa
 const NAN_MASK2: u32 = 0x0055_5555;
 
+/// Miri adds some extra errors to float functions; make sure the tests still pass.
+/// These values are purely used as a canary to test against and are thus not a stable guarantee Rust provides.
+/// They serve as a way to get an idea of the real precision of floating point operations on different platforms.
+const APPROX_DELTA: f32 = if cfg!(miri) { 1e-4 } else { 1e-6 };
+
 #[test]
 fn test_num_f32() {
     super::test_num(10f32, 2f32);
@@ -437,8 +442,8 @@ fn test_powi() {
     let nan: f32 = f32::NAN;
     let inf: f32 = f32::INFINITY;
     let neg_inf: f32 = f32::NEG_INFINITY;
-    assert_biteq!(1.0f32.powi(1), 1.0);
-    assert_approx_eq!((-3.1f32).powi(2), 9.61);
+    assert_approx_eq!(1.0f32.powi(1), 1.0);
+    assert_approx_eq!((-3.1f32).powi(2), 9.61, APPROX_DELTA);
     assert_approx_eq!(5.9f32.powi(-2), 0.028727);
     assert_biteq!(8.3f32.powi(0), 1.0);
     assert!(nan.powi(2).is_nan());
diff --git a/library/coretests/tests/floats/f64.rs b/library/coretests/tests/floats/f64.rs
index 74202a37409..dd5b67c251d 100644
--- a/library/coretests/tests/floats/f64.rs
+++ b/library/coretests/tests/floats/f64.rs
@@ -422,7 +422,7 @@ fn test_powi() {
     let nan: f64 = f64::NAN;
     let inf: f64 = f64::INFINITY;
     let neg_inf: f64 = f64::NEG_INFINITY;
-    assert_biteq!(1.0f64.powi(1), 1.0);
+    assert_approx_eq!(1.0f64.powi(1), 1.0);
     assert_approx_eq!((-3.1f64).powi(2), 9.61);
     assert_approx_eq!(5.9f64.powi(-2), 0.028727);
     assert_biteq!(8.3f64.powi(0), 1.0);
diff --git a/library/coretests/tests/num/dec2flt/float.rs b/library/coretests/tests/num/dec2flt/float.rs
index 264de061be9..2407ba50ca3 100644
--- a/library/coretests/tests/num/dec2flt/float.rs
+++ b/library/coretests/tests/num/dec2flt/float.rs
@@ -23,7 +23,8 @@ fn test_f16_integer_decode() {
 fn test_f32_integer_decode() {
     assert_eq!(3.14159265359f32.integer_decode(), (13176795, -22, 1));
     assert_eq!((-8573.5918555f32).integer_decode(), (8779358, -10, -1));
-    assert_eq!(2f32.powf(100.0).integer_decode(), (8388608, 77, 1));
+    // Set 2^100 directly instead of using powf, because it doesn't guarentee precision
+    assert_eq!(1.2676506e30_f32.integer_decode(), (8388608, 77, 1));
     assert_eq!(0f32.integer_decode(), (0, -150, 1));
     assert_eq!((-0f32).integer_decode(), (0, -150, -1));
     assert_eq!(f32::INFINITY.integer_decode(), (8388608, 105, 1));
@@ -39,7 +40,8 @@ fn test_f32_integer_decode() {
 fn test_f64_integer_decode() {
     assert_eq!(3.14159265359f64.integer_decode(), (7074237752028906, -51, 1));
     assert_eq!((-8573.5918555f64).integer_decode(), (4713381968463931, -39, -1));
-    assert_eq!(2f64.powf(100.0).integer_decode(), (4503599627370496, 48, 1));
+    // Set 2^100 directly instead of using powf, because it doesn't guarentee precision
+    assert_eq!(1.2676506002282294e30_f64.integer_decode(), (4503599627370496, 48, 1));
     assert_eq!(0f64.integer_decode(), (0, -1075, 1));
     assert_eq!((-0f64).integer_decode(), (0, -1075, -1));
     assert_eq!(f64::INFINITY.integer_decode(), (4503599627370496, 972, 1));