#include <pal.h>

/**
 *
 * Calculates the hyperbolic tangent of the input vector 'a'.
 * Angles are specified in radians.
 *
 * @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_tanh_f32(const float *a, float *c, int n)
{
    int i;
    for (i = 0; i < n; i++) {
        *(c + i) = tanhf(*(a + i));
    }
}

#include <pal.h>

#include "p_exp.h"

/*
 * tanh z = sinh z / cosh z
 *        = (exp z - exp -z) / (exp z + ezp -z)
 *        = (exp 2z - 1) / (exp 2z + 1)
 */
static inline float _p_tanh(const float z)
{
    float exp_2z = _p_exp(2.f * z);
    return (exp_2z - 1.f) / (exp_2z + 1.f);
}

/**
 *
 * Calculates the hyperbolic tangent of the input vector 'a'.
 * Angles are specified in radians.
 *
 * @param a     Pointer to input vector
 *
 * @param c     Pointer to output vector
 *
 * @param n     Size of 'a' and 'c' vector.
 *
 * @return      None
 *
 */
void p_tanh_f32(const float *a, float *c, int n)
{
    int i;
    for (i = 0; i < n; i++) {
        c[i] = _p_tanh(a[i]);
    }
}

Implement the hyperbolic tangent function.
math:tanh: Implement the hyperbolic tangent function.

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