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

Implementations on Foreign Types

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

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

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

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

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

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

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.

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.

Implementors