pub(crate) trait FloatExt {
fn log2(self) -> Self;
fn powi(self, n: i32) -> Self;
fn floor(self) -> Self;
fn ceil(self) -> Self;
fn round(self) -> Self;
}
impl FloatExt for f64 {
#[inline]
fn log2(self) -> Self {
libm::log2(self)
}
#[inline]
fn powi(self, n: i32) -> Self {
let mut acc = 1.0_f64;
let mut base = self;
let mut exp = n.unsigned_abs();
while exp > 0 {
if exp & 1 == 1 {
acc *= base;
}
exp >>= 1;
if exp > 0 {
base *= base;
}
}
if n < 0 { 1.0 / acc } else { acc }
}
#[inline]
fn floor(self) -> Self {
libm::floor(self)
}
#[inline]
fn ceil(self) -> Self {
libm::ceil(self)
}
#[inline]
fn round(self) -> Self {
libm::round(self)
}
}