mirror of https://github.com/rust-lang/rust.git
more clear NAN names and fix broken_floats logic
Co-authored-by: Jubilee <46493976+workingjubilee@users.noreply.github.com>
This commit is contained in:
parent
53e1a2ee46
commit
5f33085a7f
|
@ -46,14 +46,15 @@ fn f32() {
|
|||
|
||||
// Check that NaNs roundtrip their bits regardless of signalingness
|
||||
// 0xA is 0b1010; 0x5 is 0b0101 -- so these two together clobbers all the mantissa bits
|
||||
const MASKED_NAN1: u32 = f32::NAN.to_bits() ^ 0x002A_AAAA;
|
||||
const MASKED_NAN2: u32 = f32::NAN.to_bits() ^ 0x0055_5555;
|
||||
// NOTE: These names assume `f{BITS}::NAN` is a quiet NAN and IEEE754-2008's NaN rules apply!
|
||||
const QUIET_NAN: u32 = f32::NAN.to_bits() ^ 0x002A_AAAA;
|
||||
const SIGNALING_NAN: u32 = f32::NAN.to_bits() ^ 0x0055_5555;
|
||||
|
||||
const_assert!(f32::from_bits(MASKED_NAN1).is_nan());
|
||||
const_assert!(f32::from_bits(MASKED_NAN2).is_nan());
|
||||
const_assert!(f32::from_bits(MASKED_NAN1).to_bits(), MASKED_NAN1);
|
||||
const_assert!(f32::from_bits(QUIET_NAN).is_nan());
|
||||
const_assert!(f32::from_bits(SIGNALING_NAN).is_nan());
|
||||
const_assert!(f32::from_bits(QUIET_NAN).to_bits(), QUIET_NAN);
|
||||
if !has_broken_floats() {
|
||||
const_assert!(f32::from_bits(MASKED_NAN2).to_bits(), MASKED_NAN2);
|
||||
const_assert!(f32::from_bits(SIGNALING_NAN).to_bits(), SIGNALING_NAN);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,14 +76,15 @@ fn f64() {
|
|||
|
||||
// Check that NaNs roundtrip their bits regardless of signalingness
|
||||
// 0xA is 0b1010; 0x5 is 0b0101 -- so these two together clobbers all the mantissa bits
|
||||
const MASKED_NAN1: u64 = f64::NAN.to_bits() ^ 0x000A_AAAA_AAAA_AAAA;
|
||||
const MASKED_NAN2: u64 = f64::NAN.to_bits() ^ 0x0005_5555_5555_5555;
|
||||
// NOTE: These names assume `f{BITS}::NAN` is a quiet NAN and IEEE754-2008's NaN rules apply!
|
||||
const QUIET_NAN: u64 = f64::NAN.to_bits() ^ 0x0005_5555_5555_5555;
|
||||
const SIGNALING_NAN: u64 = f64::NAN.to_bits() ^ 0x000A_AAAA_AAAA_AAAA;
|
||||
|
||||
const_assert!(f64::from_bits(MASKED_NAN1).is_nan());
|
||||
const_assert!(f64::from_bits(MASKED_NAN2).is_nan());
|
||||
const_assert!(f64::from_bits(MASKED_NAN1).to_bits(), MASKED_NAN1);
|
||||
const_assert!(f64::from_bits(QUIET_NAN).is_nan());
|
||||
const_assert!(f64::from_bits(SIGNALING_NAN).is_nan());
|
||||
const_assert!(f64::from_bits(QUIET_NAN).to_bits(), QUIET_NAN);
|
||||
if !has_broken_floats() {
|
||||
const_assert!(f64::from_bits(MASKED_NAN2).to_bits(), MASKED_NAN2);
|
||||
const_assert!(f64::from_bits(SIGNALING_NAN).to_bits(), SIGNALING_NAN);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue