@@ -22,6 +22,11 @@ const NAN_MASK1: u32 = 0x002a_aaaa;
22
22
/// Second pattern over the mantissa
23
23
const NAN_MASK2 : u32 = 0x0055_5555 ;
24
24
25
+ /// Miri adds some extra errors to float functions; make sure the tests still pass.
26
+ /// These values are purely used as a canary to test against and are thus not a stable guarantee Rust provides.
27
+ /// They serve as a way to get an idea of the real precision of floating point operations on different platforms.
28
+ const APPROX_DETLA : f32 = if cfg ! ( miri) { 1e-4 } else { 1e-6 } ;
29
+
25
30
#[ allow( unused_macros) ]
26
31
macro_rules! assert_f32_biteq {
27
32
( $left : expr, $right : expr) => {
@@ -446,7 +451,7 @@ fn test_powi() {
446
451
assert_approx_eq ! (
447
452
( -3.1f32 ) . powi( 2 ) ,
448
453
9.61 ,
449
- 1e-4 /* Miri float-non-det: Make tests pass for now */
454
+ APPROX_DETLA /* Miri float-non-det: Make tests pass for now */
450
455
) ;
451
456
assert_approx_eq ! ( 5.9f32 . powi( -2 ) , 0.028727 ) ;
452
457
assert_eq ! ( 8.3f32 . powi( 0 ) , 1.0 ) ;
@@ -464,13 +469,13 @@ fn test_powf() {
464
469
assert_approx_eq ! (
465
470
3.4f32 . powf( 4.5 ) ,
466
471
246.408218 ,
467
- 1e-4 /* Miri float-non-det: Make tests pass for now */
472
+ APPROX_DETLA /* Miri float-non-det: Make tests pass for now */
468
473
) ;
469
474
assert_approx_eq ! ( 2.7f32 . powf( -3.2 ) , 0.041652 ) ;
470
475
assert_approx_eq ! (
471
476
( -3.1f32 ) . powf( 2.0 ) ,
472
477
9.61 ,
473
- 1e-4 /* Miri float-non-det: Make tests pass for now */
478
+ APPROX_DETLA /* Miri float-non-det: Make tests pass for now */
474
479
) ;
475
480
assert_approx_eq ! ( 5.9f32 . powf( -2.0 ) , 0.028727 ) ;
476
481
assert_eq ! ( 8.3f32 . powf( 0.0 ) , 1.0 ) ;
@@ -497,7 +502,7 @@ fn test_exp() {
497
502
assert_approx_eq ! (
498
503
148.413162 ,
499
504
5.0f32 . exp( ) ,
500
- 1e-4 /* Miri float-non-det: Make tests pass for now */
505
+ APPROX_DETLA /* Miri float-non-det: Make tests pass for now */
501
506
) ;
502
507
503
508
let inf: f32 = f32:: INFINITY ;
@@ -513,7 +518,7 @@ fn test_exp2() {
513
518
assert_approx_eq ! (
514
519
32.0 ,
515
520
5.0f32 . exp2( ) ,
516
- 1e-4 /* Miri float-non-det: Make tests pass for now */
521
+ APPROX_DETLA /* Miri float-non-det: Make tests pass for now */
517
522
) ;
518
523
assert_eq ! ( 1.0 , 0.0f32 . exp2( ) ) ;
519
524
@@ -540,7 +545,7 @@ fn test_ln() {
540
545
assert_approx_eq ! (
541
546
4.0f32 . ln( ) ,
542
547
1.386294 ,
543
- 1e-4 /* Miri float-non-det: Make tests pass for now */
548
+ APPROX_DETLA /* Miri float-non-det: Make tests pass for now */
544
549
) ;
545
550
}
546
551
@@ -666,7 +671,7 @@ fn test_acosh() {
666
671
assert_approx_eq ! (
667
672
60.0f32 ,
668
673
60.0f32 . cosh( ) . acosh( ) ,
669
- 1e-4 /* Miri float-non-det: Make tests pass for now */
674
+ APPROX_DETLA /* Miri float-non-det: Make tests pass for now */
670
675
) ;
671
676
}
672
677
@@ -749,7 +754,7 @@ fn test_real_consts() {
749
754
assert_approx_eq ! (
750
755
frac_pi_3,
751
756
pi / 3f32 ,
752
- 1e-4 /* Miri float-non-det: Make tests pass for now */
757
+ APPROX_DETLA /* Miri float-non-det: Make tests pass for now */
753
758
) ;
754
759
assert_approx_eq ! ( frac_pi_4, pi / 4f32 ) ;
755
760
assert_approx_eq ! ( frac_pi_6, pi / 6f32 ) ;
0 commit comments