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§

source

fn next_power_of_2(self) -> Self::Output

Implementations on Foreign Types§

source§

impl NextPowerOf2 for f32

source§

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

source§

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.

§

type Output = f64

source§

impl NextPowerOf2 for u8

source§

fn next_power_of_2(self) -> u8

This is a wrapper over the next_power_of_two functions in the standard library, for example this one.

§

type Output = u8

source§

impl NextPowerOf2 for u16

source§

fn next_power_of_2(self) -> u16

This is a wrapper over the next_power_of_two functions in the standard library, for example this one.

§

type Output = u16

source§

impl NextPowerOf2 for u32

source§

fn next_power_of_2(self) -> u32

This is a wrapper over the next_power_of_two functions in the standard library, for example this one.

§

type Output = u32

source§

impl NextPowerOf2 for u64

source§

fn next_power_of_2(self) -> u64

This is a wrapper over the next_power_of_two functions in the standard library, for example this one.

§

type Output = u64

source§

impl NextPowerOf2 for u128

source§

fn next_power_of_2(self) -> u128

This is a wrapper over the next_power_of_two functions in the standard library, for example this one.

§

type Output = u128

source§

impl NextPowerOf2 for usize

source§

fn next_power_of_2(self) -> usize

This is a wrapper over the next_power_of_two functions in the standard library, for example this one.

§

type Output = usize

Implementors§