Skip to content

Commit 5446ba3

Browse files
committed
float: Enable some f16 and f128 rounding tests on miri
The rounding tests are now supported, so there is no longer any reason to skip these.
1 parent 9907c5a commit 5446ba3

File tree

2 files changed

+26
-60
lines changed

2 files changed

+26
-60
lines changed

library/coretests/tests/floats/f128.rs

Lines changed: 14 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
// FIXME(f16_f128): only tested on platforms that have symbols and aren't buggy
22
#![cfg(target_has_reliable_f128)]
33

4+
use core::ops::{Add, Div, Mul, Sub};
45
use std::f128::consts;
56
use std::num::FpCategory as Fp;
6-
#[cfg(not(miri))]
7-
#[cfg(target_has_reliable_f128_math)]
8-
use std::ops::Rem;
9-
use std::ops::{Add, Div, Mul, Sub};
107

118
// Note these tolerances make sense around zero, but not for more extreme exponents.
129

@@ -49,47 +46,36 @@ fn test_num_f128() {
4946
assert_eq!(ten.sub(two), ten - two);
5047
assert_eq!(ten.mul(two), ten * two);
5148
assert_eq!(ten.div(two), ten / two);
49+
#[cfg(any(miri, target_has_reliable_f128_math))]
50+
assert_eq!(core::ops::Rem::rem(ten, two), ten % two);
5251
}
5352

5453
// FIXME(f16_f128,miri): many of these have to be disabled since miri does not yet support
5554
// the intrinsics.
5655

5756
#[test]
58-
#[cfg(not(miri))]
59-
#[cfg(target_has_reliable_f128_math)]
60-
fn test_num_f128_rem() {
61-
let ten = 10f128;
62-
let two = 2f128;
63-
assert_eq!(ten.rem(two), ten % two);
64-
}
65-
66-
#[test]
67-
#[cfg(not(miri))]
68-
#[cfg(target_has_reliable_f128_math)]
57+
#[cfg(any(miri, target_has_reliable_f128_math))]
6958
fn test_min_nan() {
7059
assert_eq!(f128::NAN.min(2.0), 2.0);
7160
assert_eq!(2.0f128.min(f128::NAN), 2.0);
7261
}
7362

7463
#[test]
75-
#[cfg(not(miri))]
76-
#[cfg(target_has_reliable_f128_math)]
64+
#[cfg(any(miri, target_has_reliable_f128_math))]
7765
fn test_max_nan() {
7866
assert_eq!(f128::NAN.max(2.0), 2.0);
7967
assert_eq!(2.0f128.max(f128::NAN), 2.0);
8068
}
8169

8270
#[test]
83-
#[cfg(not(miri))]
84-
#[cfg(target_has_reliable_f128_math)]
71+
#[cfg(any(miri, target_has_reliable_f128_math))]
8572
fn test_minimum() {
8673
assert!(f128::NAN.minimum(2.0).is_nan());
8774
assert!(2.0f128.minimum(f128::NAN).is_nan());
8875
}
8976

9077
#[test]
91-
#[cfg(not(miri))]
92-
#[cfg(target_has_reliable_f128_math)]
78+
#[cfg(any(miri, target_has_reliable_f128_math))]
9379
fn test_maximum() {
9480
assert!(f128::NAN.maximum(2.0).is_nan());
9581
assert!(2.0f128.maximum(f128::NAN).is_nan());
@@ -246,7 +232,6 @@ fn test_classify() {
246232
}
247233

248234
#[test]
249-
#[cfg(not(miri))]
250235
#[cfg(target_has_reliable_f128_math)]
251236
fn test_floor() {
252237
assert_eq!(1.0f128.floor(), 1.0f128);
@@ -262,8 +247,7 @@ fn test_floor() {
262247
}
263248

264249
#[test]
265-
#[cfg(not(miri))]
266-
#[cfg(target_has_reliable_f128_math)]
250+
#[cfg(any(miri, target_has_reliable_f128_math))]
267251
fn test_ceil() {
268252
assert_eq!(1.0f128.ceil(), 1.0f128);
269253
assert_eq!(1.3f128.ceil(), 2.0f128);
@@ -278,8 +262,7 @@ fn test_ceil() {
278262
}
279263

280264
#[test]
281-
#[cfg(not(miri))]
282-
#[cfg(target_has_reliable_f128_math)]
265+
#[cfg(any(miri, target_has_reliable_f128_math))]
283266
fn test_round() {
284267
assert_eq!(2.5f128.round(), 3.0f128);
285268
assert_eq!(1.0f128.round(), 1.0f128);
@@ -295,8 +278,7 @@ fn test_round() {
295278
}
296279

297280
#[test]
298-
#[cfg(not(miri))]
299-
#[cfg(target_has_reliable_f128_math)]
281+
#[cfg(any(miri, target_has_reliable_f128_math))]
300282
fn test_round_ties_even() {
301283
assert_eq!(2.5f128.round_ties_even(), 2.0f128);
302284
assert_eq!(1.0f128.round_ties_even(), 1.0f128);
@@ -312,8 +294,7 @@ fn test_round_ties_even() {
312294
}
313295

314296
#[test]
315-
#[cfg(not(miri))]
316-
#[cfg(target_has_reliable_f128_math)]
297+
#[cfg(any(miri, target_has_reliable_f128_math))]
317298
fn test_trunc() {
318299
assert_eq!(1.0f128.trunc(), 1.0f128);
319300
assert_eq!(1.3f128.trunc(), 1.0f128);
@@ -328,8 +309,7 @@ fn test_trunc() {
328309
}
329310

330311
#[test]
331-
#[cfg(not(miri))]
332-
#[cfg(target_has_reliable_f128_math)]
312+
#[cfg(any(miri, target_has_reliable_f128_math))]
333313
fn test_fract() {
334314
assert_eq!(1.0f128.fract(), 0.0f128);
335315
assert_eq!(1.3f128.fract(), 0.300000000000000000000000000000000039f128);
@@ -344,8 +324,7 @@ fn test_fract() {
344324
}
345325

346326
#[test]
347-
#[cfg(not(miri))]
348-
#[cfg(target_has_reliable_f128_math)]
327+
#[cfg(any(miri, target_has_reliable_f128_math))]
349328
fn test_abs() {
350329
assert_eq!(f128::INFINITY.abs(), f128::INFINITY);
351330
assert_eq!(1f128.abs(), 1f128);
@@ -463,8 +442,7 @@ fn test_mul_add() {
463442
}
464443

465444
#[test]
466-
#[cfg(not(miri))]
467-
#[cfg(target_has_reliable_f128_math)]
445+
#[cfg(any(miri, target_has_reliable_f128_math))]
468446
fn test_recip() {
469447
let nan: f128 = f128::NAN;
470448
let inf: f128 = f128::INFINITY;

library/coretests/tests/floats/f16.rs

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -50,32 +50,28 @@ fn test_num_f16() {
5050
// the intrinsics.
5151

5252
#[test]
53-
#[cfg(not(miri))]
54-
#[cfg(target_has_reliable_f16_math)]
53+
#[cfg(any(miri, target_has_reliable_f16_math))]
5554
fn test_min_nan() {
5655
assert_eq!(f16::NAN.min(2.0), 2.0);
5756
assert_eq!(2.0f16.min(f16::NAN), 2.0);
5857
}
5958

6059
#[test]
61-
#[cfg(not(miri))]
62-
#[cfg(target_has_reliable_f16_math)]
60+
#[cfg(any(miri, target_has_reliable_f16_math))]
6361
fn test_max_nan() {
6462
assert_eq!(f16::NAN.max(2.0), 2.0);
6563
assert_eq!(2.0f16.max(f16::NAN), 2.0);
6664
}
6765

6866
#[test]
69-
#[cfg(not(miri))]
70-
#[cfg(target_has_reliable_f16_math)]
67+
#[cfg(any(miri, target_has_reliable_f16_math))]
7168
fn test_minimum() {
7269
assert!(f16::NAN.minimum(2.0).is_nan());
7370
assert!(2.0f16.minimum(f16::NAN).is_nan());
7471
}
7572

7673
#[test]
77-
#[cfg(not(miri))]
78-
#[cfg(target_has_reliable_f16_math)]
74+
#[cfg(any(miri, target_has_reliable_f16_math))]
7975
fn test_maximum() {
8076
assert!(f16::NAN.maximum(2.0).is_nan());
8177
assert!(2.0f16.maximum(f16::NAN).is_nan());
@@ -232,8 +228,7 @@ fn test_classify() {
232228
}
233229

234230
#[test]
235-
#[cfg(not(miri))]
236-
#[cfg(target_has_reliable_f16_math)]
231+
#[cfg(any(miri, target_has_reliable_f16_math))]
237232
fn test_floor() {
238233
assert_eq!(1.0f16.floor(), 1.0f16);
239234
assert_eq!(1.3f16.floor(), 1.0f16);
@@ -248,8 +243,7 @@ fn test_floor() {
248243
}
249244

250245
#[test]
251-
#[cfg(not(miri))]
252-
#[cfg(target_has_reliable_f16_math)]
246+
#[cfg(any(miri, target_has_reliable_f16_math))]
253247
fn test_ceil() {
254248
assert_eq!(1.0f16.ceil(), 1.0f16);
255249
assert_eq!(1.3f16.ceil(), 2.0f16);
@@ -264,8 +258,7 @@ fn test_ceil() {
264258
}
265259

266260
#[test]
267-
#[cfg(not(miri))]
268-
#[cfg(target_has_reliable_f16_math)]
261+
#[cfg(any(miri, target_has_reliable_f16_math))]
269262
fn test_round() {
270263
assert_eq!(2.5f16.round(), 3.0f16);
271264
assert_eq!(1.0f16.round(), 1.0f16);
@@ -281,8 +274,7 @@ fn test_round() {
281274
}
282275

283276
#[test]
284-
#[cfg(not(miri))]
285-
#[cfg(target_has_reliable_f16_math)]
277+
#[cfg(any(miri, target_has_reliable_f16_math))]
286278
fn test_round_ties_even() {
287279
assert_eq!(2.5f16.round_ties_even(), 2.0f16);
288280
assert_eq!(1.0f16.round_ties_even(), 1.0f16);
@@ -298,8 +290,7 @@ fn test_round_ties_even() {
298290
}
299291

300292
#[test]
301-
#[cfg(not(miri))]
302-
#[cfg(target_has_reliable_f16_math)]
293+
#[cfg(any(miri, target_has_reliable_f16_math))]
303294
fn test_trunc() {
304295
assert_eq!(1.0f16.trunc(), 1.0f16);
305296
assert_eq!(1.3f16.trunc(), 1.0f16);
@@ -314,8 +305,7 @@ fn test_trunc() {
314305
}
315306

316307
#[test]
317-
#[cfg(not(miri))]
318-
#[cfg(target_has_reliable_f16_math)]
308+
#[cfg(any(miri, target_has_reliable_f16_math))]
319309
fn test_fract() {
320310
assert_eq!(1.0f16.fract(), 0.0f16);
321311
assert_eq!(1.3f16.fract(), 0.2998f16);
@@ -330,8 +320,7 @@ fn test_fract() {
330320
}
331321

332322
#[test]
333-
#[cfg(not(miri))]
334-
#[cfg(target_has_reliable_f16_math)]
323+
#[cfg(any(miri, target_has_reliable_f16_math))]
335324
fn test_abs() {
336325
assert_eq!(f16::INFINITY.abs(), f16::INFINITY);
337326
assert_eq!(1f16.abs(), 1f16);
@@ -449,8 +438,7 @@ fn test_mul_add() {
449438
}
450439

451440
#[test]
452-
#[cfg(not(miri))]
453-
#[cfg(target_has_reliable_f16_math)]
441+
#[cfg(any(miri, target_has_reliable_f16_math))]
454442
fn test_recip() {
455443
let nan: f16 = f16::NAN;
456444
let inf: f16 = f16::INFINITY;

0 commit comments

Comments
 (0)