pub trait CheckedLogBase<B = Self> {
    type Output;

    fn checked_log_base(self, base: B) -> Option<Self::Output>;
}
Expand description

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

Required Associated Types

Required Methods

Implementations on Foreign Types

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

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

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits() / base.significant_bits().

Panics

Panics if self is 0 or base is less than 2.

Examples

See here.

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

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

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits() / base.significant_bits().

Panics

Panics if self is 0 or base is less than 2.

Examples

See here.

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

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

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits() / base.significant_bits().

Panics

Panics if self is 0 or base is less than 2.

Examples

See here.

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

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

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits() / base.significant_bits().

Panics

Panics if self is 0 or base is less than 2.

Examples

See here.

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

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

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits() / base.significant_bits().

Panics

Panics if self is 0 or base is less than 2.

Examples

See here.

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

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

Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is self.significant_bits() / base.significant_bits().

Panics

Panics if self is 0 or base is less than 2.

Examples

See here.

Implementors