当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Rust u64.checked_next_power_of_two用法及代码示例


本文简要介绍rust语言中 u64.checked_next_power_of_two 的用法。

用法

pub const fn checked_next_power_of_two(self) -> Option<u64>

返回大于或等于 n 的 2 的最小幂。如果下一个二的幂大于该类型的最大值,则返回 None,否则将二的幂包在 Some 中。

例子

基本用法:

assert_eq!(2u64.checked_next_power_of_two(), Some(2));
assert_eq!(3u64.checked_next_power_of_two(), Some(4));
assert_eq!(u64::MAX.checked_next_power_of_two(), None);

相关用法


注:本文由纯净天空筛选整理自rust-lang.org大神的英文原创作品 u64.checked_next_power_of_two。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。