本文簡要介紹rust語言中 u32.next_power_of_two
的用法。
用法
pub const fn next_power_of_two(self) -> u32
返回大於或等於 self
的 2 的最小冪。
當返回值溢出時(即 uN
類型的 self > (1 << (N-1))
),它在調試模式下發生Panics,並且在釋放模式下返回值被包裝為 0(方法可以返回 0 的唯一情況)。
例子
基本用法:
assert_eq!(2u32.next_power_of_two(), 2);
assert_eq!(3u32.next_power_of_two(), 4);
相關用法
- Rust u32.saturating_sub用法及代碼示例
- Rust u32.unstable_next_multiple_of用法及代碼示例
- Rust u32.wrapping_pow用法及代碼示例
- Rust u32.checked_neg用法及代碼示例
- Rust u32.overflowing_add用法及代碼示例
- Rust u32.overflowing_div用法及代碼示例
- Rust u32.carrying_mul用法及代碼示例
- Rust u32.to_le_bytes用法及代碼示例
- Rust u32.wrapping_shr用法及代碼示例
- Rust u32.pow用法及代碼示例
- Rust u32.leading_ones用法及代碼示例
- Rust u32.swap_bytes用法及代碼示例
- Rust u32.count_ones用法及代碼示例
- Rust u32.log用法及代碼示例
- Rust u32.checked_log用法及代碼示例
- Rust u32.checked_pow用法及代碼示例
- Rust u32.checked_add_signed用法及代碼示例
- Rust u32.from_ne_bytes用法及代碼示例
- Rust u32.to_le用法及代碼示例
- Rust u32.checked_next_multiple_of用法及代碼示例
- Rust u32.unstable_div_ceil用法及代碼示例
- Rust u32.checked_div用法及代碼示例
- Rust u32.from_be用法及代碼示例
- Rust u32.overflowing_rem_euclid用法及代碼示例
- Rust u32.overflowing_neg用法及代碼示例
注:本文由純淨天空篩選整理自rust-lang.org大神的英文原創作品 u32.next_power_of_two。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。