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§
fn checked_log_base(self, base: B) -> Option<Self::Output>
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl CheckedLogBase for u8
impl CheckedLogBase for u8
Source§fn 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
Source§impl CheckedLogBase for u16
impl CheckedLogBase for u16
Source§fn 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
Source§impl CheckedLogBase for u32
impl CheckedLogBase for u32
Source§fn 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
Source§impl CheckedLogBase for u64
impl CheckedLogBase for u64
Source§fn 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
Source§impl CheckedLogBase for u128
impl CheckedLogBase for u128
Source§fn 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
Source§impl CheckedLogBase for usize
impl CheckedLogBase for usize
Source§fn 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.