|
5 | 5 | const IS_POWER_OF_TWO_A: bool = 0u32.is_power_of_two();
|
6 | 6 | const IS_POWER_OF_TWO_B: bool = 32u32.is_power_of_two();
|
7 | 7 | const IS_POWER_OF_TWO_C: bool = 33u32.is_power_of_two();
|
8 |
| - |
9 |
| -const NEXT_POWER_OF_TWO_A: u32 = 0u32.next_power_of_two(); |
10 |
| -const NEXT_POWER_OF_TWO_B: u8 = 2u8.next_power_of_two(); |
11 |
| -const NEXT_POWER_OF_TWO_C: u8 = 3u8.next_power_of_two(); |
12 |
| -const NEXT_POWER_OF_TWO_D: u8 = 127u8.next_power_of_two(); |
13 |
| - |
14 |
| -const CHECKED_NEXT_POWER_OF_TWO_A: Option<u32> = 0u32.checked_next_power_of_two(); |
15 |
| -const CHECKED_NEXT_POWER_OF_TWO_B: Option<u8> = 2u8.checked_next_power_of_two(); |
16 |
| -const CHECKED_NEXT_POWER_OF_TWO_C: Option<u8> = 3u8.checked_next_power_of_two(); |
17 |
| -const CHECKED_NEXT_POWER_OF_TWO_D: Option<u8> = 127u8.checked_next_power_of_two(); |
18 |
| -const CHECKED_NEXT_POWER_OF_TWO_E: Option<u8> = 129u8.checked_next_power_of_two(); |
19 |
| - |
20 |
| -const WRAPPING_NEXT_POWER_OF_TWO_A: u32 = 0u32.wrapping_next_power_of_two(); |
21 |
| -const WRAPPING_NEXT_POWER_OF_TWO_B: u8 = 2u8.wrapping_next_power_of_two(); |
22 |
| -const WRAPPING_NEXT_POWER_OF_TWO_C: u8 = 3u8.wrapping_next_power_of_two(); |
23 |
| -const WRAPPING_NEXT_POWER_OF_TWO_D: u8 = 127u8.wrapping_next_power_of_two(); |
24 |
| -const WRAPPING_NEXT_POWER_OF_TWO_E: u8 = u8::max_value().wrapping_next_power_of_two(); |
| 8 | +const IS_POWER_OF_TWO_D: bool = 3u8.is_power_of_two(); |
25 | 9 |
|
26 | 10 | fn main() {
|
27 | 11 | assert!(!IS_POWER_OF_TWO_A);
|
28 | 12 | assert!(IS_POWER_OF_TWO_B);
|
29 | 13 | assert!(!IS_POWER_OF_TWO_C);
|
30 |
| - |
31 |
| - assert_eq!(NEXT_POWER_OF_TWO_A, 2); |
32 |
| - assert_eq!(NEXT_POWER_OF_TWO_B, 2); |
33 |
| - assert_eq!(NEXT_POWER_OF_TWO_C, 4); |
34 |
| - assert_eq!(NEXT_POWER_OF_TWO_D, 128); |
35 |
| - |
36 |
| - assert_eq!(CHECKED_NEXT_POWER_OF_TWO_A, Some(2)); |
37 |
| - assert_eq!(CHECKED_NEXT_POWER_OF_TWO_B, Some(2)); |
38 |
| - assert_eq!(CHECKED_NEXT_POWER_OF_TWO_C, Some(4)); |
39 |
| - assert_eq!(CHECKED_NEXT_POWER_OF_TWO_D, Some(128)); |
40 |
| - assert_eq!(CHECKED_NEXT_POWER_OF_TWO_E, None); |
41 |
| - |
42 |
| - assert_eq!(WRAPPING_NEXT_POWER_OF_TWO_A, 2); |
43 |
| - assert_eq!(WRAPPING_NEXT_POWER_OF_TWO_B, 2); |
44 |
| - assert_eq!(WRAPPING_NEXT_POWER_OF_TWO_C, 4); |
45 |
| - assert_eq!(WRAPPING_NEXT_POWER_OF_TWO_D, 128); |
46 |
| - assert_eq!(WRAPPING_NEXT_POWER_OF_TWO_E, 0); |
| 14 | + assert!(!IS_POWER_OF_TWO_D); |
47 | 15 | }
|
0 commit comments