2024-08-31 18:30:03 -05:00
|
|
|
#![warn(clippy::manual_is_power_of_two)]
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let a = 16_u64;
|
|
|
|
|
|
|
|
let _ = a.count_ones() == 1;
|
|
|
|
let _ = a & (a - 1) == 0;
|
|
|
|
|
2024-09-05 20:23:00 -05:00
|
|
|
// Test different orders of expression
|
|
|
|
let _ = 1 == a.count_ones();
|
|
|
|
let _ = (a - 1) & a == 0;
|
|
|
|
let _ = 0 == a & (a - 1);
|
|
|
|
let _ = 0 == (a - 1) & a;
|
|
|
|
|
2024-08-31 18:30:03 -05:00
|
|
|
let b = 4_i64;
|
|
|
|
|
|
|
|
// is_power_of_two only works for unsigned integers
|
|
|
|
let _ = b.count_ones() == 1;
|
|
|
|
let _ = b & (b - 1) == 0;
|
|
|
|
}
|