<commit_before>#include <math.h>
#include <pal.h>

/*
 * 0 <= x <= ln 2
 * e^-x = 1 + a1 * x + a2 * x^2 + ... + a7 * x^7 + e(x)
 * |e(x)| <= 2 * 10^-10
 */
static inline float __p_exp_ln2(const float x)
{
    const float a1 = -0.9999999995f;
    const float a2 =  0.4999999206f;
    const float a3 = -0.1666653019f;
    const float a4 =  0.0416573475f;
    const float a5 = -0.0083013598f;
    const float a6 =  0.0013298820f;
    const float a7 = -0.0001413161f;
    float exp_x;
    exp_x = 1.f +
        a1 * x +
        a2 * x * x +
        a3 * x * x * x +
        a4 * x * x * x * x +
        a5 * x * x * x * x * x +
        a6 * x * x * x * x * x * x +
        a7 * x * x * x * x * x * x * x;
    return 1.f / exp_x;
}

/*
 * x > ln 2
 * exp x = exp(x' + ln 2) = (exp x') * 2
 */
static inline float __p_exp_pos(const float x)
{
    if (x <= M_LN2)
        return __p_exp_ln2(x);
    else
        return 2.f * __p_exp_pos(x - M_LN2);
}

static inline float _p_exp(const float x)
{
    if (x >= 0.f)
        return __p_exp_pos(x);
    else
        return 1.f / __p_exp_pos(-x);
}

/**
 *
 * Calculate exponent (e^a), where e is the base of the natural logarithm
 * (2.71828.)
 *
 * @param a     Pointer to input vector
 *<commit_msg>math:exp: Reword the function documentation a little.<commit_after>#include <math.h>
#include <pal.h>

/*
 * 0 <= x <= ln 2
 * e^-x = 1 + a1 * x + a2 * x^2 + ... + a7 * x^7 + e(x)
 * |e(x)| <= 2 * 10^-10
 */
static inline float __p_exp_ln2(const float x)
{
    const float a1 = -0.9999999995f;
    const float a2 =  0.4999999206f;
    const float a3 = -0.1666653019f;
    const float a4 =  0.0416573475f;
    const float a5 = -0.0083013598f;
    const float a6 =  0.0013298820f;
    const float a7 = -0.0001413161f;
    float exp_x;
    exp_x = 1.f +
        a1 * x +
        a2 * x * x +
        a3 * x * x * x +
        a4 * x * x * x * x +
        a5 * x * x * x * x * x +
        a6 * x * x * x * x * x * x +
        a7 * x * x * x * x * x * x * x;
    return 1.f / exp_x;
}

/*
 * x > ln 2
 * exp x = exp(x' + ln 2) = (exp x') * 2
 */
static inline float __p_exp_pos(const float x)
{
    if (x <= M_LN2)
        return __p_exp_ln2(x);
    else
        return 2.f * __p_exp_pos(x - M_LN2);
}

static inline float _p_exp(const float x)
{
    if (x >= 0.f)
        return __p_exp_pos(x);
    else
        return 1.f / __p_exp_pos(-x);
}

/**
 *
 * Calculate the exponent e^a where e is Euler's number (2.71...).
 *
 * @param a     Pointer to input vector
 *
{'fraction_non_alphanumeric': 0.15326130452180872, 'fraction_numerical': 0.09643857543017206, 'mean_word_length': 1.771618625277162, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7273043', 'n_tokens_mistral': 1210, 'n_tokens_neox': 1072, 'n_words': 317}