|
1 | 1 | // run-pass
|
2 | 2 |
|
| 3 | +#![feature(const_int_pow)] |
| 4 | +#![feature(wrapping_next_power_of_two)] |
| 5 | + |
3 | 6 | const IS_POWER_OF_TWO_A: bool = 0u32.is_power_of_two();
|
4 | 7 | const IS_POWER_OF_TWO_B: bool = 32u32.is_power_of_two();
|
5 | 8 | const IS_POWER_OF_TWO_C: bool = 33u32.is_power_of_two();
|
6 | 9 |
|
| 10 | +const POW: u8 = 3u8.pow(5); |
| 11 | + |
| 12 | +const CHECKED_POW_OK: Option<u8> = 3u8.checked_pow(5); |
| 13 | +const CHECKED_POW_OVERFLOW: Option<u8> = 3u8.checked_pow(6); |
| 14 | + |
| 15 | +const WRAPPING_POW: u8 = 3u8.wrapping_pow(6); |
| 16 | +const OVERFLOWING_POW: (u8, bool) = 3u8.overflowing_pow(6); |
| 17 | +const SATURATING_POW: u8 = 3u8.saturating_pow(6); |
| 18 | + |
| 19 | +const NEXT_POWER_OF_TWO: u32 = 3u32.next_power_of_two(); |
| 20 | + |
| 21 | +const CHECKED_NEXT_POWER_OF_TWO_OK: Option<u32> = 3u32.checked_next_power_of_two(); |
| 22 | +const CHECKED_NEXT_POWER_OF_TWO_OVERFLOW: Option<u32> = |
| 23 | + u32::max_value().checked_next_power_of_two(); |
| 24 | + |
| 25 | +const WRAPPING_NEXT_POWER_OF_TWO: u32 = |
| 26 | + u32::max_value().wrapping_next_power_of_two(); |
| 27 | + |
7 | 28 | fn main() {
|
8 | 29 | assert!(!IS_POWER_OF_TWO_A);
|
9 | 30 | assert!(IS_POWER_OF_TWO_B);
|
10 | 31 | assert!(!IS_POWER_OF_TWO_C);
|
| 32 | + |
| 33 | + assert_eq!(POW, 243); |
| 34 | + |
| 35 | + assert_eq!(CHECKED_POW_OK, Some(243)); |
| 36 | + assert_eq!(CHECKED_POW_OVERFLOW, None); |
| 37 | + |
| 38 | + assert_eq!(WRAPPING_POW, 217); |
| 39 | + assert_eq!(OVERFLOWING_POW, (217, true)); |
| 40 | + assert_eq!(SATURATING_POW, u8::max_value()); |
| 41 | + |
| 42 | + assert_eq!(NEXT_POWER_OF_TWO, 4); |
| 43 | + |
| 44 | + assert_eq!(CHECKED_NEXT_POWER_OF_TWO_OK, Some(4)); |
| 45 | + assert_eq!(CHECKED_NEXT_POWER_OF_TWO_OVERFLOW, None); |
| 46 | + |
| 47 | + assert_eq!(WRAPPING_NEXT_POWER_OF_TWO, 0); |
11 | 48 | }
|
0 commit comments