pub trait CheckedLogBase2 {
type Output;
// Required method
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§
fn checked_log_base_2(self) -> 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 CheckedLogBase2 for f32
impl CheckedLogBase2 for f32
Source§fn checked_log_base_2(self) -> Option<i64>
fn checked_log_base_2(self) -> Option<i64>
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.
type Output = i64
Source§impl CheckedLogBase2 for f64
impl CheckedLogBase2 for f64
Source§fn checked_log_base_2(self) -> Option<i64>
fn checked_log_base_2(self) -> Option<i64>
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.
type Output = i64
Source§impl CheckedLogBase2 for u8
impl CheckedLogBase2 for u8
Source§fn checked_log_base_2(self) -> Option<u64>
fn checked_log_base_2(self) -> Option<u64>
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.
type Output = u64
Source§impl CheckedLogBase2 for u16
impl CheckedLogBase2 for u16
Source§fn checked_log_base_2(self) -> Option<u64>
fn checked_log_base_2(self) -> Option<u64>
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.
type Output = u64
Source§impl CheckedLogBase2 for u32
impl CheckedLogBase2 for u32
Source§fn checked_log_base_2(self) -> Option<u64>
fn checked_log_base_2(self) -> Option<u64>
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.
type Output = u64
Source§impl CheckedLogBase2 for u64
impl CheckedLogBase2 for u64
Source§fn checked_log_base_2(self) -> Option<u64>
fn checked_log_base_2(self) -> Option<u64>
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.
type Output = u64
Source§impl CheckedLogBase2 for u128
impl CheckedLogBase2 for u128
Source§fn checked_log_base_2(self) -> Option<u64>
fn checked_log_base_2(self) -> Option<u64>
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.
type Output = u64
Source§impl CheckedLogBase2 for usize
impl CheckedLogBase2 for usize
Source§fn checked_log_base_2(self) -> Option<u64>
fn checked_log_base_2(self) -> Option<u64>
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.