micromath 2.0.0

Embedded-friendly math library featuring fast floating point approximations (with small code size) for common arithmetic operations, trigonometry, 2D/3D vector types, statistical analysis, and quaternions. Optimizes for performance and small code size at the cost of precision.
Documentation
//! arcsin approximation for a single-precision float.
//!
//! Method described at:
//! <https://dsp.stackexchange.com/questions/25770/looking-for-an-arcsin-algorithm>

use super::F32;

impl F32 {
    /// Computes `asin(x)` approximation in radians in the range `[-pi/2, pi/2]`.
    pub fn asin(self) -> Self {
        (self * (Self::ONE - self * self).invsqrt()).atan()
    }
}

#[cfg(test)]
mod tests {
    use super::F32;
    use core::f32::consts::FRAC_PI_2;

    #[test]
    fn sanity_check() {
        let difference = F32(FRAC_PI_2).sin().asin() - FRAC_PI_2;
        assert!(difference.abs() <= F32::EPSILON);
    }
}