本文简要介绍rust语言中 u64.next_power_of_two
的用法。
用法
pub const fn next_power_of_two(self) -> u64
返回大于或等于 self
的 2 的最小幂。
当返回值溢出时(即 uN
类型的 self > (1 << (N-1))
),它在调试模式下发生Panics,并且在释放模式下返回值被包装为 0(方法可以返回 0 的唯一情况)。
例子
基本用法:
assert_eq!(2u64.next_power_of_two(), 2);
assert_eq!(3u64.next_power_of_two(), 4);
相关用法
- Rust u64.rotate_right用法及代码示例
- Rust u64.overflowing_mul用法及代码示例
- Rust u64.log用法及代码示例
- Rust u64.overflowing_sub用法及代码示例
- Rust u64.carrying_mul用法及代码示例
- Rust u64.from_le_bytes用法及代码示例
- Rust u64.wrapping_shl用法及代码示例
- Rust u64.wrapping_shr用法及代码示例
- Rust u64.checked_log用法及代码示例
- Rust u64.checked_next_power_of_two用法及代码示例
- Rust u64.unstable_next_multiple_of用法及代码示例
- Rust u64.log2用法及代码示例
- Rust u64.wrapping_rem_euclid用法及代码示例
- Rust u64.overflowing_rem_euclid用法及代码示例
- Rust u64.swap_bytes用法及代码示例
- Rust u64.overflowing_add_signed用法及代码示例
- Rust u64.checked_add用法及代码示例
- Rust u64.saturating_pow用法及代码示例
- Rust u64.overflowing_neg用法及代码示例
- Rust u64.overflowing_rem用法及代码示例
- Rust u64.checked_mul用法及代码示例
- Rust u64.checked_sub用法及代码示例
- Rust u64.from_be用法及代码示例
- Rust u64.wrapping_sub用法及代码示例
- Rust u64.to_le_bytes用法及代码示例
注:本文由纯净天空筛选整理自rust-lang.org大神的英文原创作品 u64.next_power_of_two。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。