Skip to content

Commit

Permalink
improve readability of is_power_of_two
Browse files Browse the repository at this point in the history
  • Loading branch information
tspiteri committed Oct 21, 2019
1 parent a12788a commit d689c70
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/libcore/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3750,7 +3750,7 @@ assert!(!10", stringify!($SelfT), ".is_power_of_two());", $EndFeature, "
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub const fn is_power_of_two(self) -> bool {
((self.wrapping_sub(1)) & self == 0) & !(self == 0)
self.count_ones() == 1
}
}

Expand Down

0 comments on commit d689c70

Please sign in to comment.