Rollup merge of #140149 - RalfJung:test_nan, r=tgross35

test_nan: ensure the NAN contant is quiet

Follow-up to https://github.com/rust-lang/rust/pull/139483

r? ``@tgross35``
This commit is contained in:
Chris Denton 2025-04-22 15:24:09 +00:00 committed by GitHub
commit 2d8264fb08
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 20 additions and 0 deletions

View File

@ -145,6 +145,9 @@ impl f128 {
pub const RADIX: u32 = 2;
/// Number of significant digits in base 2.
///
/// Note that the size of the mantissa in the bitwise representation is one
/// smaller than this since the leading 1 is not stored explicitly.
#[unstable(feature = "f128", issue = "116909")]
pub const MANTISSA_DIGITS: u32 = 113;

View File

@ -140,6 +140,9 @@ impl f16 {
pub const RADIX: u32 = 2;
/// Number of significant digits in base 2.
///
/// Note that the size of the mantissa in the bitwise representation is one
/// smaller than this since the leading 1 is not stored explicitly.
#[unstable(feature = "f16", issue = "116909")]
pub const MANTISSA_DIGITS: u32 = 11;

View File

@ -390,6 +390,9 @@ impl f32 {
pub const RADIX: u32 = 2;
/// Number of significant digits in base 2.
///
/// Note that the size of the mantissa in the bitwise representation is one
/// smaller than this since the leading 1 is not stored explicitly.
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
pub const MANTISSA_DIGITS: u32 = 24;

View File

@ -390,6 +390,9 @@ impl f64 {
pub const RADIX: u32 = 2;
/// Number of significant digits in base 2.
///
/// Note that the size of the mantissa in the bitwise representation is one
/// smaller than this since the leading 1 is not stored explicitly.
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
pub const MANTISSA_DIGITS: u32 = 53;
/// Approximate number of significant digits in base 10.

View File

@ -112,6 +112,8 @@ fn test_nan() {
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]

View File

@ -95,6 +95,8 @@ fn test_nan() {
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]

View File

@ -72,6 +72,8 @@ fn test_nan() {
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]

View File

@ -60,6 +60,8 @@ fn test_nan() {
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]