From 73eba2e3576c4f64262e605ad805020bb888fdee Mon Sep 17 00:00:00 2001 From: Steve Akinyemi Date: Wed, 7 Nov 2018 19:03:52 +0100 Subject: [PATCH] Fix wrong for bit mask canonical nan --- src/spectests/_common.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/spectests/_common.rs b/src/spectests/_common.rs index e20de8b5fed..2a6044dee4a 100644 --- a/src/spectests/_common.rs +++ b/src/spectests/_common.rs @@ -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 } } @@ -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 } }