pub trait CheckedLogBasePowerOf2<POW> {
    type Output;

    // Required method
    fn checked_log_base_power_of_2(self, pow: POW) -> Option<Self::Output>;
}
Expand description

Calculates the base-$2^k$ logarithm of a number, or returns None if the number is not a perfect power of $2^k$.

Required Associated Types§

Required Methods§

source

fn checked_log_base_power_of_2(self, pow: POW) -> Option<Self::Output>

Implementations on Foreign Types§

source§

impl CheckedLogBasePowerOf2<u64> for f32

source§

fn checked_log_base_power_of_2(self, pow: u64) -> Option<i64>

Returns the base-$2^k$ logarithm of a positive float. If the float is not a power of $2^k$, None is returned.

$$ f(x, k) = \begin{cases} \operatorname{Some}(\log_{2^k} x) & \text{if} \quad \log_{2^k} x \in \Z, \\ \operatorname{None} & \textrm{otherwise}. \end{cases} $$

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if self or pow are 0.

§Examples

See here.

§

type Output = i64

source§

impl CheckedLogBasePowerOf2<u64> for f64

source§

fn checked_log_base_power_of_2(self, pow: u64) -> Option<i64>

Returns the base-$2^k$ logarithm of a positive float. If the float is not a power of $2^k$, None is returned.

$$ f(x, k) = \begin{cases} \operatorname{Some}(\log_{2^k} x) & \text{if} \quad \log_{2^k} x \in \Z, \\ \operatorname{None} & \textrm{otherwise}. \end{cases} $$

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if self or pow are 0.

§Examples

See here.

§

type Output = i64

source§

impl CheckedLogBasePowerOf2<u64> for u8

source§

fn checked_log_base_power_of_2(self, pow: u64) -> Option<u64>

Returns the base-$2^k$ logarithm of a positive integer. If the integer is not a power of $2^k$, None is returned.

$$ f(x, k) = \begin{cases} \operatorname{Some}(\log_{2^k} x) & \text{if} \quad \log_{2^k} x \in \Z, \\ \operatorname{None} & \textrm{otherwise}. \end{cases} $$

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if self is infinite, NaN, or less than or equal to zero, or if pow is zero.

§Examples

See here.

§

type Output = u64

source§

impl CheckedLogBasePowerOf2<u64> for u16

source§

fn checked_log_base_power_of_2(self, pow: u64) -> Option<u64>

Returns the base-$2^k$ logarithm of a positive integer. If the integer is not a power of $2^k$, None is returned.

$$ f(x, k) = \begin{cases} \operatorname{Some}(\log_{2^k} x) & \text{if} \quad \log_{2^k} x \in \Z, \\ \operatorname{None} & \textrm{otherwise}. \end{cases} $$

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if self is infinite, NaN, or less than or equal to zero, or if pow is zero.

§Examples

See here.

§

type Output = u64

source§

impl CheckedLogBasePowerOf2<u64> for u32

source§

fn checked_log_base_power_of_2(self, pow: u64) -> Option<u64>

Returns the base-$2^k$ logarithm of a positive integer. If the integer is not a power of $2^k$, None is returned.

$$ f(x, k) = \begin{cases} \operatorname{Some}(\log_{2^k} x) & \text{if} \quad \log_{2^k} x \in \Z, \\ \operatorname{None} & \textrm{otherwise}. \end{cases} $$

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if self is infinite, NaN, or less than or equal to zero, or if pow is zero.

§Examples

See here.

§

type Output = u64

source§

impl CheckedLogBasePowerOf2<u64> for u64

source§

fn checked_log_base_power_of_2(self, pow: u64) -> Option<u64>

Returns the base-$2^k$ logarithm of a positive integer. If the integer is not a power of $2^k$, None is returned.

$$ f(x, k) = \begin{cases} \operatorname{Some}(\log_{2^k} x) & \text{if} \quad \log_{2^k} x \in \Z, \\ \operatorname{None} & \textrm{otherwise}. \end{cases} $$

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if self is infinite, NaN, or less than or equal to zero, or if pow is zero.

§Examples

See here.

§

type Output = u64

source§

impl CheckedLogBasePowerOf2<u64> for u128

source§

fn checked_log_base_power_of_2(self, pow: u64) -> Option<u64>

Returns the base-$2^k$ logarithm of a positive integer. If the integer is not a power of $2^k$, None is returned.

$$ f(x, k) = \begin{cases} \operatorname{Some}(\log_{2^k} x) & \text{if} \quad \log_{2^k} x \in \Z, \\ \operatorname{None} & \textrm{otherwise}. \end{cases} $$

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if self is infinite, NaN, or less than or equal to zero, or if pow is zero.

§Examples

See here.

§

type Output = u64

source§

impl CheckedLogBasePowerOf2<u64> for usize

source§

fn checked_log_base_power_of_2(self, pow: u64) -> Option<u64>

Returns the base-$2^k$ logarithm of a positive integer. If the integer is not a power of $2^k$, None is returned.

$$ f(x, k) = \begin{cases} \operatorname{Some}(\log_{2^k} x) & \text{if} \quad \log_{2^k} x \in \Z, \\ \operatorname{None} & \textrm{otherwise}. \end{cases} $$

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if self is infinite, NaN, or less than or equal to zero, or if pow is zero.

§Examples

See here.

§

type Output = u64

Implementors§