#[inline]
pub(crate) fn ipow64(x: f64, n: i32) -> f64 {
let mut base = x;
let mut e = n.unsigned_abs();
let mut acc = 1.0f64;
while e > 0 {
if e & 1 == 1 {
acc *= base;
}
e >>= 1;
if e > 0 {
base *= base;
}
}
if n < 0 {
1.0 / acc
} else {
acc
}
}
#[cfg(not(feature = "std"))]
pub trait FloatExt: Sized {
fn mul_add(self, a: Self, b: Self) -> Self;
fn sqrt(self) -> Self;
fn ceil(self) -> Self;
fn floor(self) -> Self;
fn round(self) -> Self;
}
#[cfg(not(feature = "std"))]
impl FloatExt for f64 {
#[inline]
fn mul_add(self, a: Self, b: Self) -> Self {
libm::fma(self, a, b)
}
#[inline]
fn sqrt(self) -> Self {
libm::sqrt(self)
}
#[inline]
fn ceil(self) -> Self {
libm::ceil(self)
}
#[inline]
fn floor(self) -> Self {
libm::floor(self)
}
#[inline]
fn round(self) -> Self {
libm::round(self)
}
}
#[inline]
#[allow(clippy::cast_precision_loss)]
pub(crate) const fn u64_f64(n: u64) -> f64 {
n as f64
}
#[inline]
#[allow(clippy::cast_precision_loss)]
pub(crate) const fn usize_f64(n: usize) -> f64 {
n as f64
}
#[inline]
#[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)]
pub(crate) fn f64_usize(x: f64) -> usize {
x.max(0.0) as usize
}
#[inline]
#[allow(clippy::cast_possible_truncation)]
pub(crate) const fn hash_index(h: u64) -> usize {
h as usize
}
#[inline]
#[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)]
pub(crate) fn f64_u64(x: f64) -> u64 {
x as u64
}
#[inline]
#[allow(clippy::cast_possible_truncation)]
pub(crate) fn f64_i64(x: f64) -> i64 {
x as i64
}
#[inline]
#[allow(clippy::cast_precision_loss)]
pub(crate) const fn i64_f64(x: i64) -> f64 {
x as f64
}
#[inline]
#[allow(clippy::cast_possible_truncation)]
pub(crate) fn f64_i32(x: f64) -> i32 {
x as i32
}