#[cfg(all(not(feature = "libm"), feature = "std"))]
#[expect(
clippy::disallowed_methods,
reason = "Many of the disallowed methods are disallowed to force code to use the feature-conditional re-exports from this module, but this module itself is exempt from that rule."
)]
mod std_ops {
#[inline]
pub fn powf(x: f32, y: f32) -> f32 {
f32::powf(x, y)
}
#[inline]
pub fn exp(x: f32) -> f32 {
f32::exp(x)
}
#[inline]
pub fn exp2(x: f32) -> f32 {
f32::exp2(x)
}
#[inline]
pub fn ln(x: f32) -> f32 {
f32::ln(x)
}
#[inline]
pub fn log2(x: f32) -> f32 {
f32::log2(x)
}
#[inline]
pub fn log10(x: f32) -> f32 {
f32::log10(x)
}
#[inline]
pub fn cbrt(x: f32) -> f32 {
f32::cbrt(x)
}
#[inline]
pub fn hypot(x: f32, y: f32) -> f32 {
f32::hypot(x, y)
}
#[inline]
pub fn sin(x: f32) -> f32 {
f32::sin(x)
}
#[inline]
pub fn cos(x: f32) -> f32 {
f32::cos(x)
}
#[inline]
pub fn tan(x: f32) -> f32 {
f32::tan(x)
}
#[inline]
pub fn asin(x: f32) -> f32 {
f32::asin(x)
}
#[inline]
pub fn acos(x: f32) -> f32 {
f32::acos(x)
}
#[inline]
pub fn atan(x: f32) -> f32 {
f32::atan(x)
}
#[inline]
pub fn atan2(y: f32, x: f32) -> f32 {
f32::atan2(y, x)
}
#[inline]
pub fn sin_cos(x: f32) -> (f32, f32) {
f32::sin_cos(x)
}
#[inline]
pub fn exp_m1(x: f32) -> f32 {
f32::exp_m1(x)
}
#[inline]
pub fn ln_1p(x: f32) -> f32 {
f32::ln_1p(x)
}
#[inline]
pub fn sinh(x: f32) -> f32 {
f32::sinh(x)
}
#[inline]
pub fn cosh(x: f32) -> f32 {
f32::cosh(x)
}
#[inline]
pub fn tanh(x: f32) -> f32 {
f32::tanh(x)
}
#[inline]
pub fn asinh(x: f32) -> f32 {
f32::asinh(x)
}
#[inline]
pub fn acosh(x: f32) -> f32 {
f32::acosh(x)
}
#[inline]
pub fn atanh(x: f32) -> f32 {
f32::atanh(x)
}
}
#[cfg(any(feature = "libm", all(feature = "nostd-libm", not(feature = "std"))))]
mod libm_ops {
#[inline]
pub fn powf(x: f32, y: f32) -> f32 {
libm::powf(x, y)
}
#[inline]
pub fn exp(x: f32) -> f32 {
libm::expf(x)
}
#[inline]
pub fn exp2(x: f32) -> f32 {
libm::exp2f(x)
}
#[inline]
pub fn ln(x: f32) -> f32 {
libm::logf(x)
}
#[inline]
pub fn log2(x: f32) -> f32 {
libm::log2f(x)
}
#[inline]
pub fn log10(x: f32) -> f32 {
libm::log10f(x)
}
#[inline]
pub fn cbrt(x: f32) -> f32 {
libm::cbrtf(x)
}
#[inline]
pub fn hypot(x: f32, y: f32) -> f32 {
libm::hypotf(x, y)
}
#[inline]
pub fn sin(x: f32) -> f32 {
libm::sinf(x)
}
#[inline]
pub fn cos(x: f32) -> f32 {
libm::cosf(x)
}
#[inline]
pub fn tan(x: f32) -> f32 {
libm::tanf(x)
}
#[inline]
pub fn asin(x: f32) -> f32 {
libm::asinf(x)
}
#[inline]
pub fn acos(x: f32) -> f32 {
libm::acosf(x)
}
#[inline]
pub fn atan(x: f32) -> f32 {
libm::atanf(x)
}
#[inline]
pub fn atan2(y: f32, x: f32) -> f32 {
libm::atan2f(y, x)
}
#[inline]
pub fn sin_cos(x: f32) -> (f32, f32) {
libm::sincosf(x)
}
#[inline]
pub fn exp_m1(x: f32) -> f32 {
libm::expm1f(x)
}
#[inline]
pub fn ln_1p(x: f32) -> f32 {
libm::log1pf(x)
}
#[inline]
pub fn sinh(x: f32) -> f32 {
libm::sinhf(x)
}
#[inline]
pub fn cosh(x: f32) -> f32 {
libm::coshf(x)
}
#[inline]
pub fn tanh(x: f32) -> f32 {
libm::tanhf(x)
}
#[inline]
pub fn asinh(x: f32) -> f32 {
libm::asinhf(x)
}
#[inline]
pub fn acosh(x: f32) -> f32 {
libm::acoshf(x)
}
#[inline]
pub fn atanh(x: f32) -> f32 {
libm::atanhf(x)
}
}
#[cfg(all(any(feature = "libm", feature = "nostd-libm"), not(feature = "std")))]
mod libm_ops_for_no_std {
#[inline]
pub fn rem_euclid(x: f32, y: f32) -> f32 {
let result = libm::remainderf(x, y);
if result < 0. {
result + y
} else {
result
}
}
#[inline]
pub fn abs(x: f32) -> f32 {
libm::fabsf(x)
}
#[inline]
pub fn sqrt(x: f32) -> f32 {
libm::sqrtf(x)
}
#[inline]
pub fn copysign(x: f32, y: f32) -> f32 {
libm::copysignf(x, y)
}
#[inline]
pub fn round(x: f32) -> f32 {
libm::roundf(x)
}
#[inline]
pub fn floor(x: f32) -> f32 {
libm::floorf(x)
}
#[inline]
pub fn ceil(x: f32) -> f32 {
libm::ceilf(x)
}
#[inline]
pub fn fract(x: f32) -> f32 {
libm::modff(x).0
}
}
#[cfg(feature = "std")]
#[expect(
clippy::disallowed_methods,
reason = "Many of the disallowed methods are disallowed to force code to use the feature-conditional re-exports from this module, but this module itself is exempt from that rule."
)]
mod std_ops_for_no_std {
#[inline]
pub fn rem_euclid(x: f32, y: f32) -> f32 {
f32::rem_euclid(x, y)
}
#[inline]
pub fn abs(x: f32) -> f32 {
f32::abs(x)
}
#[inline]
pub fn sqrt(x: f32) -> f32 {
f32::sqrt(x)
}
#[inline]
pub fn copysign(x: f32, y: f32) -> f32 {
f32::copysign(x, y)
}
#[inline]
pub fn round(x: f32) -> f32 {
f32::round(x)
}
#[inline]
pub fn floor(x: f32) -> f32 {
f32::floor(x)
}
#[inline]
pub fn ceil(x: f32) -> f32 {
f32::ceil(x)
}
#[inline]
pub fn fract(x: f32) -> f32 {
f32::fract(x)
}
}
#[cfg(any(feature = "libm", all(feature = "nostd-libm", not(feature = "std"))))]
pub use libm_ops::*;
#[cfg(all(not(feature = "libm"), feature = "std"))]
pub use std_ops::*;
#[cfg(feature = "std")]
pub use std_ops_for_no_std::*;
#[cfg(all(any(feature = "libm", feature = "nostd-libm"), not(feature = "std")))]
pub use libm_ops_for_no_std::*;
#[cfg(all(
not(feature = "libm"),
not(feature = "std"),
not(feature = "nostd-libm")
))]
compile_error!("Either the `libm`, `std`, or `nostd-libm` feature must be enabled.");
pub trait FloatPow {
fn squared(self) -> Self;
fn cubed(self) -> Self;
}
impl FloatPow for f32 {
#[inline]
fn squared(self) -> Self {
self * self
}
#[inline]
fn cubed(self) -> Self {
self * self * self
}
}