Skip to content

Commit 9af7bda

Browse files
authored
Rollup merge of #143396 - rocurley:float_tests_refactor, r=tgross35
Move NaN tests to floats/mod.rs This PR moves NaN tests to `floats/mod.rs`, as discussed in #141726. Since this is my first PR against Rust, I'm keeping it as small as possible, but I intend to work my way through the remaining tests and can do that work in this PR if that's preferable. r? RalfJung
2 parents 7ad9096 + bc2001f commit 9af7bda

File tree

5 files changed

+23
-56
lines changed

5 files changed

+23
-56
lines changed

library/coretests/tests/floats/f128.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,6 @@ fn test_num_f128() {
5555
// FIXME(f16_f128,miri): many of these have to be disabled since miri does not yet support
5656
// the intrinsics.
5757

58-
#[test]
59-
fn test_nan() {
60-
let nan: f128 = f128::NAN;
61-
assert!(nan.is_nan());
62-
assert!(!nan.is_infinite());
63-
assert!(!nan.is_finite());
64-
assert!(nan.is_sign_positive());
65-
assert!(!nan.is_sign_negative());
66-
assert!(!nan.is_normal());
67-
assert_eq!(Fp::Nan, nan.classify());
68-
// Ensure the quiet bit is set.
69-
assert!(nan.to_bits() & (1 << (f128::MANTISSA_DIGITS - 2)) != 0);
70-
}
71-
7258
#[test]
7359
fn test_infinity() {
7460
let inf: f128 = f128::INFINITY;

library/coretests/tests/floats/f16.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,6 @@ fn test_num_f16() {
5151
// FIXME(f16_f128,miri): many of these have to be disabled since miri does not yet support
5252
// the intrinsics.
5353

54-
#[test]
55-
fn test_nan() {
56-
let nan: f16 = f16::NAN;
57-
assert!(nan.is_nan());
58-
assert!(!nan.is_infinite());
59-
assert!(!nan.is_finite());
60-
assert!(nan.is_sign_positive());
61-
assert!(!nan.is_sign_negative());
62-
assert!(!nan.is_normal());
63-
assert_eq!(Fp::Nan, nan.classify());
64-
// Ensure the quiet bit is set.
65-
assert!(nan.to_bits() & (1 << (f16::MANTISSA_DIGITS - 2)) != 0);
66-
}
67-
6854
#[test]
6955
fn test_infinity() {
7056
let inf: f16 = f16::INFINITY;

library/coretests/tests/floats/f32.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,6 @@ fn test_num_f32() {
3535
super::test_num(10f32, 2f32);
3636
}
3737

38-
#[test]
39-
fn test_nan() {
40-
let nan: f32 = f32::NAN;
41-
assert!(nan.is_nan());
42-
assert!(!nan.is_infinite());
43-
assert!(!nan.is_finite());
44-
assert!(!nan.is_normal());
45-
assert!(nan.is_sign_positive());
46-
assert!(!nan.is_sign_negative());
47-
assert_eq!(Fp::Nan, nan.classify());
48-
// Ensure the quiet bit is set.
49-
assert!(nan.to_bits() & (1 << (f32::MANTISSA_DIGITS - 2)) != 0);
50-
}
51-
5238
#[test]
5339
fn test_infinity() {
5440
let inf: f32 = f32::INFINITY;

library/coretests/tests/floats/f64.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,6 @@ fn test_num_f64() {
3030
super::test_num(10f64, 2f64);
3131
}
3232

33-
#[test]
34-
fn test_nan() {
35-
let nan: f64 = f64::NAN;
36-
assert!(nan.is_nan());
37-
assert!(!nan.is_infinite());
38-
assert!(!nan.is_finite());
39-
assert!(!nan.is_normal());
40-
assert!(nan.is_sign_positive());
41-
assert!(!nan.is_sign_negative());
42-
assert_eq!(Fp::Nan, nan.classify());
43-
// Ensure the quiet bit is set.
44-
assert!(nan.to_bits() & (1 << (f64::MANTISSA_DIGITS - 2)) != 0);
45-
}
46-
4733
#[test]
4834
fn test_infinity() {
4935
let inf: f64 = f64::INFINITY;

library/coretests/tests/floats/mod.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::fmt;
2+
use std::num::FpCategory as Fp;
23
use std::ops::{Add, Div, Mul, Rem, Sub};
34

45
/// Set the default tolerance for float comparison based on the type.
@@ -187,6 +188,8 @@ macro_rules! float_test {
187188
mod const_ {
188189
#[allow(unused)]
189190
use super::Approx;
191+
#[allow(unused)]
192+
use std::num::FpCategory as Fp;
190193
// Shadow the runtime versions of the macro with const-compatible versions.
191194
#[allow(unused)]
192195
use $crate::floats::{
@@ -250,6 +253,26 @@ mod f16;
250253
mod f32;
251254
mod f64;
252255

256+
float_test! {
257+
name: nan,
258+
attrs: {
259+
f16: #[cfg(any(miri, target_has_reliable_f16))],
260+
f128: #[cfg(any(miri, target_has_reliable_f128))],
261+
},
262+
test<Float> {
263+
let nan: Float = Float::NAN;
264+
assert!(nan.is_nan());
265+
assert!(!nan.is_infinite());
266+
assert!(!nan.is_finite());
267+
assert!(!nan.is_normal());
268+
assert!(nan.is_sign_positive());
269+
assert!(!nan.is_sign_negative());
270+
assert!(matches!(nan.classify(), Fp::Nan));
271+
// Ensure the quiet bit is set.
272+
assert!(nan.to_bits() & (1 << (Float::MANTISSA_DIGITS - 2)) != 0);
273+
}
274+
}
275+
253276
float_test! {
254277
name: min,
255278
attrs: {

0 commit comments

Comments
 (0)