/*-*-c-*-*/

/*
 * ufuncs to compute logit(p) = log(p/(1-p)) and
 * expit(x) = 1/(1+exp(-x))
 */

#include <Python.h>
#include <math.h>

#include "numpy/npy_math.h"
#include "_logit.h"

/*
 * Inner loops for logit and expit
 */

/**begin repeat
 * #type = npy_float, npy_double, npy_longdouble#
 * #c = f,,l#
 */

@type@ logit@c@(@type@ x)
{
    x /= 1 - x;
    return npy_log@c@(x);
}

@type@ expit@c@(@type@ x)
{
    if (x > 0) {
        x = npy_exp@c@(x);
        return x / (1 + x);
    }
    else {
        return 1 / (1 + npy_exp@c@(-x));
    }
}

/**end repeat**/
