pub trait CheckedLogBase2 {
    type Output;

    fn checked_log_base_2(self) -> Option<Self::Output>;
}
Expand description

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

Required Associated Types

Required Methods

Implementations on Foreign Types

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

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if self is 0.

Examples

See here.

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

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if self is 0.

Examples

See here.

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

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if self is 0.

Examples

See here.

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

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if self is 0.

Examples

See here.

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

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if self is 0.

Examples

See here.

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

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if self is 0.

Examples

See here.

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

$$ f(x) = \begin{cases} \operatorname{Some}(\log_2 x) & \text{if} \quad \log_2 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.

Examples

See here.

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

$$ f(x) = \begin{cases} \operatorname{Some}(\log_2 x) & \text{if} \quad \log_2 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.

Examples

See here.

Implementors