Trait malachite_base::num::arithmetic::traits::NextPowerOf2
source · [−]pub trait NextPowerOf2 {
type Output;
fn next_power_of_2(self) -> Self::Output;
}
Expand description
Returns the smallest power of 2 greater than or equal to a number. Assumes the result is representable.
Required Associated Types
Required Methods
fn next_power_of_2(self) -> Self::Output
Implementations on Foreign Types
sourceimpl NextPowerOf2 for u8
impl NextPowerOf2 for u8
sourceimpl NextPowerOf2 for u16
impl NextPowerOf2 for u16
sourceimpl NextPowerOf2 for u32
impl NextPowerOf2 for u32
sourceimpl NextPowerOf2 for u64
impl NextPowerOf2 for u64
sourceimpl NextPowerOf2 for u128
impl NextPowerOf2 for u128
sourceimpl NextPowerOf2 for usize
impl NextPowerOf2 for usize
sourceimpl NextPowerOf2 for f32
impl NextPowerOf2 for f32
sourcefn next_power_of_2(self) -> f32
fn next_power_of_2(self) -> f32
Finds the smallest power of 2 greater than or equal to a number.
$x \gets 2^{\lceil \log_2 x \rceil}$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if self
has a negative sign (positive zero is allowed, but negative zero
is not), or if the next power of 2 is greater than the type’s maximum value.
Examples
See here.
type Output = f32
sourceimpl NextPowerOf2 for f64
impl NextPowerOf2 for f64
sourcefn next_power_of_2(self) -> f64
fn next_power_of_2(self) -> f64
Finds the smallest power of 2 greater than or equal to a number.
$x \gets 2^{\lceil \log_2 x \rceil}$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if self
has a negative sign (positive zero is allowed, but negative zero
is not), or if the next power of 2 is greater than the type’s maximum value.
Examples
See here.