Skip to content

Commit

Permalink
more clear NAN names and fix broken_floats logic
Browse files Browse the repository at this point in the history
Co-authored-by: Jubilee <[email protected]>
  • Loading branch information
RalfJung and workingjubilee authored Aug 17, 2024
1 parent ec1cb80 commit 5811ab9
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions tests/ui/consts/const-float-bits-conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}

Expand Down

0 comments on commit 5811ab9

Please sign in to comment.