#include <pal.h>

/**
 *
 * Calculates inverse tangent (arc tangent) of the input value. The function
 * returns a value between -pi/2 to pi/2 but does not check for illegal input
 * values.
 *
 * @param a     Pointer to input vector
 *
 * @param c     Pointer to output vector
 *
 * @param n     Size of 'a' and 'c' vector.
 * 
 * @return      None
 *
 */
#include <math.h>
void p_atan_f32(const float *a, float *c, int n)
{

    int i;
    for (i = 0; i < n; i++) {
        *(c + i) = atan(*(a + i));
    }
}

#include <pal.h>

/*
 * -1 <= x <= 1
 * atan x = a1 * x + a3 * x^3 + ... + a9 * x^9 + e(x)
 * |e(x)| <= 10^-5
 */
static inline float _p_atan(const float x)
{
    const float a1 =  0.9998660f;
    const float a3 = -0.3302995f;
    const float a5 =  0.1801410f;
    const float a7 = -0.0851330f;
    const float a9 =  0.0208351f;
    return a1 * x +
        a3 * x * x * x +
        a5 * x * x * x * x * x +
        a7 * x * x * x * x * x * x * x +
        a9 * x * x * x * x * x * x * x * x * x;
}

/**
 *
 * Calculates inverse tangent (arc tangent) of the input value. The function
 * returns a value between -pi/2 to pi/2 but does not check for illegal input
 * values.
 *
 * @param a     Pointer to input vector
 *
 * @param c     Pointer to output vector
 *
 * @param n     Size of 'a' and 'c' vector.
 * 
 * @return      None
 *
 */
#include <math.h>
void p_atan_f32(const float *a, float *c, int n)
{

    int i;
    for (i = 0; i < n; i++) {
        c[i] = _p_atan(a[i]);
    }
}

Implement the inverse tangent function.
math:atan: Implement the inverse tangent function.

Signed-off-by: Mansour Moufid <ac5f6b12fab5e0d4efa7215e6c2dac9d55ab77dc@gmail.com>
