Skip to content

Commit d689c70

Browse files
committed
improve readability of is_power_of_two
1 parent a12788a commit d689c70

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/libcore/num/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3750,7 +3750,7 @@ assert!(!10", stringify!($SelfT), ".is_power_of_two());", $EndFeature, "
37503750
#[stable(feature = "rust1", since = "1.0.0")]
37513751
#[inline]
37523752
pub const fn is_power_of_two(self) -> bool {
3753-
((self.wrapping_sub(1)) & self == 0) & !(self == 0)
3753+
self.count_ones() == 1
37543754
}
37553755
}
37563756

0 commit comments

Comments
 (0)