@@ -3,7 +3,7 @@ use std::f32::consts;
33/// Miri adds some extra errors to float functions; make sure the tests still pass.
44/// These values are purely used as a canary to test against and are thus not a stable guarantee Rust provides.
55/// They serve as a way to get an idea of the real precision of floating point operations on different platforms.
6- const APPROX_DELTA : f32 = if cfg ! ( miri) { 1e-4 } else { 1e-6 } ;
6+ const APPROX_DELTA : f32 = if cfg ! ( miri) { 1e-3 } else { 1e-6 } ;
77
88#[ allow( unused_macros) ]
99macro_rules! assert_f32_biteq {
@@ -22,17 +22,9 @@ fn test_powf() {
2222 let inf: f32 = f32:: INFINITY ;
2323 let neg_inf: f32 = f32:: NEG_INFINITY ;
2424 assert_eq ! ( 1.0f32 . powf( 1.0 ) , 1.0 ) ;
25- assert_approx_eq ! (
26- 3.4f32 . powf( 4.5 ) ,
27- 246.408218 ,
28- APPROX_DELTA /* Miri float-non-det: Make tests pass for now */
29- ) ;
25+ assert_approx_eq ! ( 3.4f32 . powf( 4.5 ) , 246.408218 , APPROX_DELTA ) ;
3026 assert_approx_eq ! ( 2.7f32 . powf( -3.2 ) , 0.041652 ) ;
31- assert_approx_eq ! (
32- ( -3.1f32 ) . powf( 2.0 ) ,
33- 9.61 ,
34- APPROX_DELTA /* Miri float-non-det: Make tests pass for now */
35- ) ;
27+ assert_approx_eq ! ( ( -3.1f32 ) . powf( 2.0 ) , 9.61 , APPROX_DELTA ) ;
3628 assert_approx_eq ! ( 5.9f32 . powf( -2.0 ) , 0.028727 ) ;
3729 assert_eq ! ( 8.3f32 . powf( 0.0 ) , 1.0 ) ;
3830 assert ! ( nan. powf( 2.0 ) . is_nan( ) ) ;
@@ -44,11 +36,7 @@ fn test_powf() {
4436fn test_exp ( ) {
4537 assert_eq ! ( 1.0 , 0.0f32 . exp( ) ) ;
4638 assert_approx_eq ! ( 2.718282 , 1.0f32 . exp( ) , APPROX_DELTA ) ;
47- assert_approx_eq ! (
48- 148.413162 ,
49- 5.0f32 . exp( ) ,
50- APPROX_DELTA /* Miri float-non-det: Make tests pass for now */
51- ) ;
39+ assert_approx_eq ! ( 148.413162 , 5.0f32 . exp( ) , APPROX_DELTA ) ;
5240
5341 let inf: f32 = f32:: INFINITY ;
5442 let neg_inf: f32 = f32:: NEG_INFINITY ;
@@ -60,11 +48,7 @@ fn test_exp() {
6048
6149#[ test]
6250fn test_exp2 ( ) {
63- assert_approx_eq ! (
64- 32.0 ,
65- 5.0f32 . exp2( ) ,
66- APPROX_DELTA /* Miri float-non-det: Make tests pass for now */
67- ) ;
51+ assert_approx_eq ! ( 32.0 , 5.0f32 . exp2( ) , APPROX_DELTA ) ;
6852 assert_eq ! ( 1.0 , 0.0f32 . exp2( ) ) ;
6953
7054 let inf: f32 = f32:: INFINITY ;
@@ -87,11 +71,7 @@ fn test_ln() {
8771 assert ! ( ( -2.3f32 ) . ln( ) . is_nan( ) ) ;
8872 assert_eq ! ( ( -0.0f32 ) . ln( ) , neg_inf) ;
8973 assert_eq ! ( 0.0f32 . ln( ) , neg_inf) ;
90- assert_approx_eq ! (
91- 4.0f32 . ln( ) ,
92- 1.386294 ,
93- APPROX_DELTA /* Miri float-non-det: Make tests pass for now */
94- ) ;
74+ assert_approx_eq ! ( 4.0f32 . ln( ) , 1.386294 , APPROX_DELTA ) ;
9575}
9676
9777#[ test]
@@ -101,7 +81,7 @@ fn test_log() {
10181 let neg_inf: f32 = f32:: NEG_INFINITY ;
10282 assert_approx_eq ! ( 10.0f32 . log( 10.0 ) , 1.0 ) ;
10383 assert_approx_eq ! ( 2.3f32 . log( 3.5 ) , 0.664858 ) ;
104- assert_approx_eq ! ( 1.0f32 . exp( ) . log( 1.0f32 . exp( ) ) , 1.0 ) ;
84+ assert_approx_eq ! ( 1.0f32 . exp( ) . log( 1.0f32 . exp( ) ) , 1.0 , APPROX_DELTA ) ;
10585 assert ! ( 1.0f32 . log( 1.0 ) . is_nan( ) ) ;
10686 assert ! ( 1.0f32 . log( -13.9 ) . is_nan( ) ) ;
10787 assert ! ( nan. log( 2.3 ) . is_nan( ) ) ;
@@ -117,17 +97,9 @@ fn test_log2() {
11797 let nan: f32 = f32:: NAN ;
11898 let inf: f32 = f32:: INFINITY ;
11999 let neg_inf: f32 = f32:: NEG_INFINITY ;
120- assert_approx_eq ! (
121- 10.0f32 . log2( ) ,
122- 3.321928 ,
123- APPROX_DELTA /* Miri float-non-det: Make tests pass for now */
124- ) ;
100+ assert_approx_eq ! ( 10.0f32 . log2( ) , 3.321928 , APPROX_DELTA ) ;
125101 assert_approx_eq ! ( 2.3f32 . log2( ) , 1.201634 ) ;
126- assert_approx_eq ! (
127- 1.0f32 . exp( ) . log2( ) ,
128- 1.442695 ,
129- APPROX_DELTA /* Miri float-non-det: Make tests pass for now */
130- ) ;
102+ assert_approx_eq ! ( 1.0f32 . exp( ) . log2( ) , 1.442695 , APPROX_DELTA ) ;
131103 assert ! ( nan. log2( ) . is_nan( ) ) ;
132104 assert_eq ! ( inf. log2( ) , inf) ;
133105 assert ! ( neg_inf. log2( ) . is_nan( ) ) ;
@@ -191,11 +163,7 @@ fn test_acosh() {
191163 assert_approx_eq ! ( 3.0f32 . acosh( ) , 1.76274717403908605046521864995958461f32 ) ;
192164
193165 // test for low accuracy from issue 104548
194- assert_approx_eq ! (
195- 60.0f32 ,
196- 60.0f32 . cosh( ) . acosh( ) ,
197- APPROX_DELTA /* Miri float-non-det: Make tests pass for now */
198- ) ;
166+ assert_approx_eq ! ( 60.0f32 , 60.0f32 . cosh( ) . acosh( ) , APPROX_DELTA ) ;
199167}
200168
201169#[ test]
@@ -274,11 +242,7 @@ fn test_real_consts() {
274242 let ln_10: f32 = consts:: LN_10 ;
275243
276244 assert_approx_eq ! ( frac_pi_2, pi / 2f32 ) ;
277- assert_approx_eq ! (
278- frac_pi_3,
279- pi / 3f32 ,
280- APPROX_DELTA /* Miri float-non-det: Make tests pass for now */
281- ) ;
245+ assert_approx_eq ! ( frac_pi_3, pi / 3f32 , APPROX_DELTA ) ;
282246 assert_approx_eq ! ( frac_pi_4, pi / 4f32 ) ;
283247 assert_approx_eq ! ( frac_pi_6, pi / 6f32 ) ;
284248 assert_approx_eq ! ( frac_pi_8, pi / 8f32 ) ;
@@ -290,9 +254,5 @@ fn test_real_consts() {
290254 assert_approx_eq ! ( log2_e, e. log2( ) ) ;
291255 assert_approx_eq ! ( log10_e, e. log10( ) ) ;
292256 assert_approx_eq ! ( ln_2, 2f32 . ln( ) ) ;
293- assert_approx_eq ! (
294- ln_10,
295- 10f32 . ln( ) ,
296- APPROX_DELTA /* Miri float-non-det: Make tests pass for now */
297- ) ;
257+ assert_approx_eq ! ( ln_10, 10f32 . ln( ) , APPROX_DELTA ) ;
298258}
0 commit comments