Trait malachite_base::num::arithmetic::traits::CheckedLogBase2
source · 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>
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.