Skip to content

Commit 6864ec4

Browse files
authored
Rollup merge of rust-lang#140149 - RalfJung:test_nan, r=tgross35
test_nan: ensure the NAN contant is quiet Follow-up to rust-lang#139483 r? `@tgross35`
2 parents 268d8d4 + 5717623 commit 6864ec4

File tree

8 files changed

+20
-0
lines changed

8 files changed

+20
-0
lines changed

library/core/src/num/f128.rs

+3
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ impl f128 {
145145
pub const RADIX: u32 = 2;
146146

147147
/// Number of significant digits in base 2.
148+
///
149+
/// Note that the size of the mantissa in the bitwise representation is one
150+
/// smaller than this since the leading 1 is not stored explicitly.
148151
#[unstable(feature = "f128", issue = "116909")]
149152
pub const MANTISSA_DIGITS: u32 = 113;
150153

library/core/src/num/f16.rs

+3
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ impl f16 {
140140
pub const RADIX: u32 = 2;
141141

142142
/// Number of significant digits in base 2.
143+
///
144+
/// Note that the size of the mantissa in the bitwise representation is one
145+
/// smaller than this since the leading 1 is not stored explicitly.
143146
#[unstable(feature = "f16", issue = "116909")]
144147
pub const MANTISSA_DIGITS: u32 = 11;
145148

library/core/src/num/f32.rs

+3
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,9 @@ impl f32 {
390390
pub const RADIX: u32 = 2;
391391

392392
/// Number of significant digits in base 2.
393+
///
394+
/// Note that the size of the mantissa in the bitwise representation is one
395+
/// smaller than this since the leading 1 is not stored explicitly.
393396
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
394397
pub const MANTISSA_DIGITS: u32 = 24;
395398

library/core/src/num/f64.rs

+3
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,9 @@ impl f64 {
390390
pub const RADIX: u32 = 2;
391391

392392
/// Number of significant digits in base 2.
393+
///
394+
/// Note that the size of the mantissa in the bitwise representation is one
395+
/// smaller than this since the leading 1 is not stored explicitly.
393396
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
394397
pub const MANTISSA_DIGITS: u32 = 53;
395398
/// Approximate number of significant digits in base 10.

library/std/tests/floats/f128.rs

+2
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ fn test_nan() {
112112
assert!(!nan.is_sign_negative());
113113
assert!(!nan.is_normal());
114114
assert_eq!(Fp::Nan, nan.classify());
115+
// Ensure the quiet bit is set.
116+
assert!(nan.to_bits() & (1 << (f128::MANTISSA_DIGITS - 2)) != 0);
115117
}
116118

117119
#[test]

library/std/tests/floats/f16.rs

+2
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ fn test_nan() {
9595
assert!(!nan.is_sign_negative());
9696
assert!(!nan.is_normal());
9797
assert_eq!(Fp::Nan, nan.classify());
98+
// Ensure the quiet bit is set.
99+
assert!(nan.to_bits() & (1 << (f16::MANTISSA_DIGITS - 2)) != 0);
98100
}
99101

100102
#[test]

library/std/tests/floats/f32.rs

+2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ fn test_nan() {
7272
assert!(nan.is_sign_positive());
7373
assert!(!nan.is_sign_negative());
7474
assert_eq!(Fp::Nan, nan.classify());
75+
// Ensure the quiet bit is set.
76+
assert!(nan.to_bits() & (1 << (f32::MANTISSA_DIGITS - 2)) != 0);
7577
}
7678

7779
#[test]

library/std/tests/floats/f64.rs

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ fn test_nan() {
6060
assert!(nan.is_sign_positive());
6161
assert!(!nan.is_sign_negative());
6262
assert_eq!(Fp::Nan, nan.classify());
63+
// Ensure the quiet bit is set.
64+
assert!(nan.to_bits() & (1 << (f64::MANTISSA_DIGITS - 2)) != 0);
6365
}
6466

6567
#[test]

0 commit comments

Comments
 (0)