Skip to content

Commit

Permalink
Merge pull request #8 from appcypher/fix/canonical-nan-bit-mask
Browse files Browse the repository at this point in the history
Fix canonical nan test function
  • Loading branch information
syrusakbary authored Nov 7, 2018
2 parents 58c6822 + 73eba2e commit 9227e16
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/spectests/_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ impl NaNCheck for f32 {
self.is_nan() && (self.to_bits() & bit_mask) == bit_mask
}

/// For a NaN to be canonical, its mantissa bits must all be set,
/// only the MSB is disregarded. (i.e we don't care if the MSB of the mantissa is set or not)
/// For a NaN to be canonical, its mantissa bits must all be unset
fn is_canonical_nan(&self) -> bool {
let bit_mask = 0b0____1111_1111____011_1111_1111_1111_1111_1111;
(self.to_bits() & bit_mask) == bit_mask
let bit_mask: u32 = 0b1____0000_0000____011_1111_1111_1111_1111_1111;
let masked_value = self.to_bits() ^ bit_mask;
masked_value == 0xFFFF_FFFF || masked_value == 0x7FFF_FFFF
}
}

Expand All @@ -57,11 +57,11 @@ impl NaNCheck for f64 {
self.is_nan() && (self.to_bits() & bit_mask) == bit_mask
}

/// For a NaN to be canonical, its mantissa bits must all be set,
/// only the MSB is disregarded. (i.e we don't care if the MSB of the mantissa is set or not)
/// For a NaN to be canonical, its mantissa bits must all be unset
fn is_canonical_nan(&self) -> bool {
// 0b0____111_1111_1111____0111_1111_1111_1111 ... 1111
let bit_mask = 0x7FF7FFFFFFFFFFFF;
(self.to_bits() & bit_mask) == bit_mask
let bit_mask: u64 =
0b1____000_0000_0000____0111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111;
let masked_value = self.to_bits() ^ bit_mask;
masked_value == 0x7FFF_FFFF_FFFF_FFFF || masked_value == 0xFFF_FFFF_FFFF_FFFF
}
}

0 comments on commit 9227e16

Please sign in to comment.