#[cfg(feature = "libm")]
#[allow(unused_imports)]
use num_traits::Float;
pub(crate) trait FloatEx {
fn acos_approx(self) -> Self;
}
impl FloatEx for f32 {
#[inline(always)]
fn acos_approx(self) -> Self {
let nonnegative = self >= 0.0;
let x = self.abs();
let mut omx = 1.0 - x;
if omx < 0.0 {
omx = 0.0;
}
let root = omx.sqrt();
#[allow(clippy::approx_constant)]
let mut result = ((((((-0.001_262_491_1 * x + 0.006_670_09) * x - 0.017_088_126) * x
+ 0.030_891_88)
* x
- 0.050_174_303)
* x
+ 0.088_978_99)
* x
- 0.214_598_8)
* x
+ 1.570_796_3;
result *= root;
if nonnegative {
result
} else {
core::f32::consts::PI - result
}
}
}
impl FloatEx for f64 {
#[inline(always)]
fn acos_approx(self) -> Self {
f64::acos(self.clamp(-1.0, 1.0))
}
}