1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use crate::num::arithmetic::traits::IsPowerOf2;
use crate::num::conversion::traits::IntegerMantissaAndExponent;
macro_rules! impl_is_power_of_2_unsigned {
($t:ident) => {
impl IsPowerOf2 for $t {
#[inline]
fn is_power_of_2(&self) -> bool {
$t::is_power_of_two(*self)
}
}
};
}
apply_to_unsigneds!(impl_is_power_of_2_unsigned);
macro_rules! impl_is_power_of_2_primitive_float {
($t:ident) => {
impl IsPowerOf2 for $t {
#[inline]
fn is_power_of_2(&self) -> bool {
self.is_finite() && *self > 0.0 && self.integer_mantissa() == 1
}
}
};
}
apply_to_primitive_floats!(impl_is_power_of_2_primitive_float);