Trait malachite_base::num::arithmetic::traits::NextPowerOf2
source · pub trait NextPowerOf2 {
type Output;
// Required method
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§
source§impl NextPowerOf2 for f32
impl NextPowerOf2 for f32
source§fn 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
source§impl NextPowerOf2 for f64
impl NextPowerOf2 for f64
source§fn 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.