Module malachite_base::num::arithmetic::next_power_of_2
source · Expand description
NextPowerOf2
and NextPowerOf2Assign
,
traits for getting the next-highest power of 2.
§next_power_of_2
use malachite_base::num::arithmetic::traits::NextPowerOf2;
assert_eq!(100.0f32.next_power_of_2(), 128.0);
assert_eq!(0.01f32.next_power_of_2(), 0.015625);
§next_power_of_2_assign
use malachite_base::num::arithmetic::traits::NextPowerOf2Assign;
let mut x = 0u8;
x.next_power_of_2_assign();
assert_eq!(x, 1);
let mut x = 4u16;
x.next_power_of_2_assign();
assert_eq!(x, 4);
let mut x = 10u32;
x.next_power_of_2_assign();
assert_eq!(x, 16);
let mut x = (1u64 << 40) - 5;
x.next_power_of_2_assign();
assert_eq!(x, 1 << 40);
let mut x = 100.0f32;
x.next_power_of_2_assign();
assert_eq!(x, 128.0);
let mut x = 0.01f32;
x.next_power_of_2_assign();
assert_eq!(x, 0.015625);