Trait malachite_base::num::arithmetic::traits::CheckedLogBase

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

    // Required method
    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§

source

fn checked_log_base(self, base: B) -> Option<Self::Output>

Implementations on Foreign Types§

source§

impl CheckedLogBase for u8

source§

fn checked_log_base(self, base: u8) -> Option<u64>

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.

§

type Output = u64

source§

impl CheckedLogBase for u16

source§

fn checked_log_base(self, base: u16) -> Option<u64>

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.

§

type Output = u64

source§

impl CheckedLogBase for u32

source§

fn checked_log_base(self, base: u32) -> Option<u64>

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.

§

type Output = u64

source§

impl CheckedLogBase for u64

source§

fn checked_log_base(self, base: u64) -> Option<u64>

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.

§

type Output = u64

source§

impl CheckedLogBase for u128

source§

fn checked_log_base(self, base: u128) -> Option<u64>

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.

§

type Output = u64

source§

impl CheckedLogBase for usize

source§

fn checked_log_base(self, base: usize) -> Option<u64>

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.

§

type Output = u64

Implementors§