1
Fork 0

improve readability of is_power_of_two

This commit is contained in:
Trevor Spiteri 2019-10-21 15:35:54 +02:00
parent a12788a0d7
commit d689c709ea

View file

@ -3750,7 +3750,7 @@ assert!(!10", stringify!($SelfT), ".is_power_of_two());", $EndFeature, "
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[inline] #[inline]
pub const fn is_power_of_two(self) -> bool { pub const fn is_power_of_two(self) -> bool {
((self.wrapping_sub(1)) & self == 0) & !(self == 0) self.count_ones() == 1
} }
} }