Trait malachite_base::num::arithmetic::traits::CheckedLogBase
source · [−]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
fn checked_log_base(self, base: B) -> Option<Self::Output>
Implementations on Foreign Types
sourceimpl CheckedLogBase<u8> for u8
impl CheckedLogBase<u8> for u8
sourcefn checked_log_base(self, base: u8) -> Option<u64>
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
sourceimpl CheckedLogBase<u16> for u16
impl CheckedLogBase<u16> for u16
sourcefn checked_log_base(self, base: u16) -> Option<u64>
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
sourceimpl CheckedLogBase<u32> for u32
impl CheckedLogBase<u32> for u32
sourcefn checked_log_base(self, base: u32) -> Option<u64>
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
sourceimpl CheckedLogBase<u64> for u64
impl CheckedLogBase<u64> for u64
sourcefn checked_log_base(self, base: u64) -> Option<u64>
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
sourceimpl CheckedLogBase<u128> for u128
impl CheckedLogBase<u128> for u128
sourcefn checked_log_base(self, base: u128) -> Option<u64>
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
sourceimpl CheckedLogBase<usize> for usize
impl CheckedLogBase<usize> for usize
sourcefn checked_log_base(self, base: usize) -> Option<u64>
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.