pub trait CheckedLogBasePowerOf2<POW> {
    type Output;

    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

Implementations on Foreign Types

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.

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.

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.

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.

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.

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.

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.

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.

Implementors