Skip to content

Move NaN tests to floats/mod.rs #143396

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions library/coretests/tests/floats/f128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,6 @@ fn test_num_f128() {
// FIXME(f16_f128,miri): many of these have to be disabled since miri does not yet support
// the intrinsics.

#[test]
fn test_nan() {
let nan: f128 = f128::NAN;
assert!(nan.is_nan());
assert!(!nan.is_infinite());
assert!(!nan.is_finite());
assert!(nan.is_sign_positive());
assert!(!nan.is_sign_negative());
assert!(!nan.is_normal());
assert_eq!(Fp::Nan, nan.classify());
// Ensure the quiet bit is set.
assert!(nan.to_bits() & (1 << (f128::MANTISSA_DIGITS - 2)) != 0);
}

#[test]
fn test_infinity() {
let inf: f128 = f128::INFINITY;
Expand Down
14 changes: 0 additions & 14 deletions library/coretests/tests/floats/f16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,6 @@ fn test_num_f16() {
// FIXME(f16_f128,miri): many of these have to be disabled since miri does not yet support
// the intrinsics.

#[test]
fn test_nan() {
let nan: f16 = f16::NAN;
assert!(nan.is_nan());
assert!(!nan.is_infinite());
assert!(!nan.is_finite());
assert!(nan.is_sign_positive());
assert!(!nan.is_sign_negative());
assert!(!nan.is_normal());
assert_eq!(Fp::Nan, nan.classify());
// Ensure the quiet bit is set.
assert!(nan.to_bits() & (1 << (f16::MANTISSA_DIGITS - 2)) != 0);
}

#[test]
fn test_infinity() {
let inf: f16 = f16::INFINITY;
Expand Down
14 changes: 0 additions & 14 deletions library/coretests/tests/floats/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,6 @@ fn test_num_f32() {
super::test_num(10f32, 2f32);
}

#[test]
fn test_nan() {
let nan: f32 = f32::NAN;
assert!(nan.is_nan());
assert!(!nan.is_infinite());
assert!(!nan.is_finite());
assert!(!nan.is_normal());
assert!(nan.is_sign_positive());
assert!(!nan.is_sign_negative());
assert_eq!(Fp::Nan, nan.classify());
// Ensure the quiet bit is set.
assert!(nan.to_bits() & (1 << (f32::MANTISSA_DIGITS - 2)) != 0);
}

#[test]
fn test_infinity() {
let inf: f32 = f32::INFINITY;
Expand Down
14 changes: 0 additions & 14 deletions library/coretests/tests/floats/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,6 @@ fn test_num_f64() {
super::test_num(10f64, 2f64);
}

#[test]
fn test_nan() {
let nan: f64 = f64::NAN;
assert!(nan.is_nan());
assert!(!nan.is_infinite());
assert!(!nan.is_finite());
assert!(!nan.is_normal());
assert!(nan.is_sign_positive());
assert!(!nan.is_sign_negative());
assert_eq!(Fp::Nan, nan.classify());
// Ensure the quiet bit is set.
assert!(nan.to_bits() & (1 << (f64::MANTISSA_DIGITS - 2)) != 0);
}

#[test]
fn test_infinity() {
let inf: f64 = f64::INFINITY;
Expand Down
21 changes: 21 additions & 0 deletions library/coretests/tests/floats/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -695,3 +695,24 @@ float_test! {
assert!(Float::NEG_INFINITY.fract().is_nan());
}
}

float_test! {
name: nan,
attrs: {
f16: #[cfg(any(miri, target_has_reliable_f16_math))],
f128: #[cfg(any(miri, target_has_reliable_f128_math))],
Comment on lines +702 to +703
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, noticed something; could you use target_has_reliable_f{16,128} rather than the _math versions? _math is only for anything that calls libm functions, which these don't.

Mind also moving this above the other float_test instances? Might as well keep things ordered setup-> basic tests -> math tests, like the other test files.

},
test<Float> {
use std::num::FpCategory as Fp;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The as Fp is copied from the original tests, but I don't actually see much reason for it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move it to the top of this file instead? The short form makes a bit more sense with the other infinite/finite/etc tests that also use it. (Not that we need to shorten it but 🤷‍♂ )

let nan: Float = Float::NAN;
assert!(nan.is_nan());
assert!(!nan.is_infinite());
assert!(!nan.is_finite());
assert!(!nan.is_normal());
assert!(nan.is_sign_positive());
assert!(!nan.is_sign_negative());
assert!(matches!(nan.classify(), Fp::Nan));
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is changed from an assert_eq to work in a const context.

// Ensure the quiet bit is set.
assert!(nan.to_bits() & (1 << (Float::MANTISSA_DIGITS - 2)) != 0);
}
}
Loading