Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix canonical nan test function #8

Merged
merged 1 commit into from
Nov 7, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}