Skip to content

Commit 9c047e7

Browse files
committed
fixup! float: Enable some f16 and f128 rounding tests on miri
1 parent 5925932 commit 9c047e7

File tree

2 files changed

+26
-46
lines changed

2 files changed

+26
-46
lines changed

library/coretests/tests/floats/f128.rs

Lines changed: 14 additions & 29 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_biteq!(ten.sub(two), ten - two);
5047
assert_biteq!(ten.mul(two), ten * two);
5148
assert_biteq!(ten.div(two), ten / two);
49+
#[cfg(any(miri, target_has_reliable_f128_math))]
50+
assert_biteq!(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_biteq!(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_biteq!(f128::NAN.min(2.0), 2.0);
7160
assert_biteq!(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_biteq!(f128::NAN.max(2.0), 2.0);
7967
assert_biteq!(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());
@@ -262,7 +248,7 @@ fn test_floor() {
262248
}
263249

264250
#[test]
265-
#[cfg(target_has_reliable_f128_math)]
251+
#[cfg(any(miri, target_has_reliable_f128_math))]
266252
fn test_ceil() {
267253
assert_biteq!(1.0f128.ceil(), 1.0f128);
268254
assert_biteq!(1.3f128.ceil(), 2.0f128);
@@ -277,7 +263,7 @@ fn test_ceil() {
277263
}
278264

279265
#[test]
280-
#[cfg(target_has_reliable_f128_math)]
266+
#[cfg(any(miri, target_has_reliable_f128_math))]
281267
fn test_round() {
282268
assert_biteq!(2.5f128.round(), 3.0f128);
283269
assert_biteq!(1.0f128.round(), 1.0f128);
@@ -293,7 +279,7 @@ fn test_round() {
293279
}
294280

295281
#[test]
296-
#[cfg(target_has_reliable_f128_math)]
282+
#[cfg(any(miri, target_has_reliable_f128_math))]
297283
fn test_round_ties_even() {
298284
assert_biteq!(2.5f128.round_ties_even(), 2.0f128);
299285
assert_biteq!(1.0f128.round_ties_even(), 1.0f128);
@@ -309,7 +295,7 @@ fn test_round_ties_even() {
309295
}
310296

311297
#[test]
312-
#[cfg(target_has_reliable_f128_math)]
298+
#[cfg(any(miri, target_has_reliable_f128_math))]
313299
fn test_trunc() {
314300
assert_biteq!(1.0f128.trunc(), 1.0f128);
315301
assert_biteq!(1.3f128.trunc(), 1.0f128);
@@ -324,7 +310,7 @@ fn test_trunc() {
324310
}
325311

326312
#[test]
327-
#[cfg(target_has_reliable_f128_math)]
313+
#[cfg(any(miri, target_has_reliable_f128_math))]
328314
fn test_fract() {
329315
assert_biteq!(1.0f128.fract(), 0.0f128);
330316
assert_biteq!(1.3f128.fract(), 0.300000000000000000000000000000000039f128);
@@ -339,7 +325,7 @@ fn test_fract() {
339325
}
340326

341327
#[test]
342-
#[cfg(target_has_reliable_f128_math)]
328+
#[cfg(any(miri, target_has_reliable_f128_math))]
343329
fn test_abs() {
344330
assert_biteq!(f128::INFINITY.abs(), f128::INFINITY);
345331
assert_biteq!(1f128.abs(), 1f128);
@@ -457,8 +443,7 @@ fn test_mul_add() {
457443
}
458444

459445
#[test]
460-
#[cfg(not(miri))]
461-
#[cfg(target_has_reliable_f128_math)]
446+
#[cfg(any(miri, target_has_reliable_f128_math))]
462447
fn test_recip() {
463448
let nan: f128 = f128::NAN;
464449
let inf: f128 = f128::INFINITY;

library/coretests/tests/floats/f16.rs

Lines changed: 12 additions & 17 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_biteq!(f16::NAN.min(2.0), 2.0);
5756
assert_biteq!(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_biteq!(f16::NAN.max(2.0), 2.0);
6563
assert_biteq!(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());
@@ -233,7 +229,7 @@ fn test_classify() {
233229
}
234230

235231
#[test]
236-
#[cfg(target_has_reliable_f16_math)]
232+
#[cfg(any(miri, target_has_reliable_f16_math))]
237233
fn test_floor() {
238234
assert_biteq!(1.0f16.floor(), 1.0f16);
239235
assert_biteq!(1.3f16.floor(), 1.0f16);
@@ -248,7 +244,7 @@ fn test_floor() {
248244
}
249245

250246
#[test]
251-
#[cfg(target_has_reliable_f16_math)]
247+
#[cfg(any(miri, target_has_reliable_f16_math))]
252248
fn test_ceil() {
253249
assert_biteq!(1.0f16.ceil(), 1.0f16);
254250
assert_biteq!(1.3f16.ceil(), 2.0f16);
@@ -263,7 +259,7 @@ fn test_ceil() {
263259
}
264260

265261
#[test]
266-
#[cfg(target_has_reliable_f16_math)]
262+
#[cfg(any(miri, target_has_reliable_f16_math))]
267263
fn test_round() {
268264
assert_biteq!(2.5f16.round(), 3.0f16);
269265
assert_biteq!(1.0f16.round(), 1.0f16);
@@ -279,7 +275,7 @@ fn test_round() {
279275
}
280276

281277
#[test]
282-
#[cfg(target_has_reliable_f16_math)]
278+
#[cfg(any(miri, target_has_reliable_f16_math))]
283279
fn test_round_ties_even() {
284280
assert_biteq!(2.5f16.round_ties_even(), 2.0f16);
285281
assert_biteq!(1.0f16.round_ties_even(), 1.0f16);
@@ -295,7 +291,7 @@ fn test_round_ties_even() {
295291
}
296292

297293
#[test]
298-
#[cfg(target_has_reliable_f16_math)]
294+
#[cfg(any(miri, target_has_reliable_f16_math))]
299295
fn test_trunc() {
300296
assert_biteq!(1.0f16.trunc(), 1.0f16);
301297
assert_biteq!(1.3f16.trunc(), 1.0f16);
@@ -310,7 +306,7 @@ fn test_trunc() {
310306
}
311307

312308
#[test]
313-
#[cfg(target_has_reliable_f16_math)]
309+
#[cfg(any(miri, target_has_reliable_f16_math))]
314310
fn test_fract() {
315311
assert_biteq!(1.0f16.fract(), 0.0f16);
316312
assert_biteq!(1.3f16.fract(), 0.2998f16);
@@ -325,7 +321,7 @@ fn test_fract() {
325321
}
326322

327323
#[test]
328-
#[cfg(target_has_reliable_f16_math)]
324+
#[cfg(any(miri, target_has_reliable_f16_math))]
329325
fn test_abs() {
330326
assert_biteq!(f16::INFINITY.abs(), f16::INFINITY);
331327
assert_biteq!(1f16.abs(), 1f16);
@@ -443,8 +439,7 @@ fn test_mul_add() {
443439
}
444440

445441
#[test]
446-
#[cfg(not(miri))]
447-
#[cfg(target_has_reliable_f16_math)]
442+
#[cfg(any(miri, target_has_reliable_f16_math))]
448443
fn test_recip() {
449444
let nan: f16 = f16::NAN;
450445
let inf: f16 = f16::INFINITY;

0 commit comments

Comments
 (0)