1//! arcsin approximation for a single-precision float.
2//!
3//! Method described at:
4//! <https://dsp.stackexchange.com/questions/25770/looking-for-an-arcsin-algorithm>
5
6use super::F32;
7
8impl F32 {
9 /// Computes `asin(x)` approximation in radians in the range `[-pi/2, pi/2]`.
10 pub fn asin(self) -> Self {
11 (self * (Self::ONE - self * self).invsqrt()).atan()
12 }
13}
14
15#[cfg(test)]
16mod tests {
17 use super::F32;
18 use core::f32::consts::FRAC_PI_2;
19
20 #[test]
21 fn sanity_check() {
22 let difference = F32(FRAC_PI_2).sin().asin() - FRAC_PI_2;
23 assert!(difference.abs() <= F32::EPSILON);
24 }
25}
26