@@ -3,7 +3,7 @@ use std::f32::consts;
3
3
/// Miri adds some extra errors to float functions; make sure the tests still pass.
4
4
/// These values are purely used as a canary to test against and are thus not a stable guarantee Rust provides.
5
5
/// 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 } ;
7
7
8
8
#[ allow( unused_macros) ]
9
9
macro_rules! assert_f32_biteq {
@@ -22,17 +22,9 @@ fn test_powf() {
22
22
let inf: f32 = f32:: INFINITY ;
23
23
let neg_inf: f32 = f32:: NEG_INFINITY ;
24
24
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 ) ;
30
26
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 ) ;
36
28
assert_approx_eq ! ( 5.9f32 . powf( -2.0 ) , 0.028727 ) ;
37
29
assert_eq ! ( 8.3f32 . powf( 0.0 ) , 1.0 ) ;
38
30
assert ! ( nan. powf( 2.0 ) . is_nan( ) ) ;
@@ -44,11 +36,7 @@ fn test_powf() {
44
36
fn test_exp ( ) {
45
37
assert_eq ! ( 1.0 , 0.0f32 . exp( ) ) ;
46
38
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 ) ;
52
40
53
41
let inf: f32 = f32:: INFINITY ;
54
42
let neg_inf: f32 = f32:: NEG_INFINITY ;
@@ -60,11 +48,7 @@ fn test_exp() {
60
48
61
49
#[ test]
62
50
fn 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 ) ;
68
52
assert_eq ! ( 1.0 , 0.0f32 . exp2( ) ) ;
69
53
70
54
let inf: f32 = f32:: INFINITY ;
@@ -87,11 +71,7 @@ fn test_ln() {
87
71
assert ! ( ( -2.3f32 ) . ln( ) . is_nan( ) ) ;
88
72
assert_eq ! ( ( -0.0f32 ) . ln( ) , neg_inf) ;
89
73
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 ) ;
95
75
}
96
76
97
77
#[ test]
@@ -101,7 +81,7 @@ fn test_log() {
101
81
let neg_inf: f32 = f32:: NEG_INFINITY ;
102
82
assert_approx_eq ! ( 10.0f32 . log( 10.0 ) , 1.0 ) ;
103
83
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 ) ;
105
85
assert ! ( 1.0f32 . log( 1.0 ) . is_nan( ) ) ;
106
86
assert ! ( 1.0f32 . log( -13.9 ) . is_nan( ) ) ;
107
87
assert ! ( nan. log( 2.3 ) . is_nan( ) ) ;
@@ -117,17 +97,9 @@ fn test_log2() {
117
97
let nan: f32 = f32:: NAN ;
118
98
let inf: f32 = f32:: INFINITY ;
119
99
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 ) ;
125
101
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 ) ;
131
103
assert ! ( nan. log2( ) . is_nan( ) ) ;
132
104
assert_eq ! ( inf. log2( ) , inf) ;
133
105
assert ! ( neg_inf. log2( ) . is_nan( ) ) ;
@@ -191,11 +163,7 @@ fn test_acosh() {
191
163
assert_approx_eq ! ( 3.0f32 . acosh( ) , 1.76274717403908605046521864995958461f32 ) ;
192
164
193
165
// 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 ) ;
199
167
}
200
168
201
169
#[ test]
@@ -274,11 +242,7 @@ fn test_real_consts() {
274
242
let ln_10: f32 = consts:: LN_10 ;
275
243
276
244
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 ) ;
282
246
assert_approx_eq ! ( frac_pi_4, pi / 4f32 ) ;
283
247
assert_approx_eq ! ( frac_pi_6, pi / 6f32 ) ;
284
248
assert_approx_eq ! ( frac_pi_8, pi / 8f32 ) ;
@@ -290,9 +254,5 @@ fn test_real_consts() {
290
254
assert_approx_eq ! ( log2_e, e. log2( ) ) ;
291
255
assert_approx_eq ! ( log10_e, e. log10( ) ) ;
292
256
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 ) ;
298
258
}
0 commit comments