Robust implementations of derivative of the log cdf of a standard normal.

     @see [[https://github.com/mseeger/apbsint/blob/master/src/eptools/potentials/SpecfunServices.h original implementation]]
     in C from Matthias Seeger.

def derivLogCdfNormal(z):
    """
     Robust implementations of derivative of the log cdf of a standard normal.

     @see [[https://github.com/mseeger/apbsint/blob/master/src/eptools/potentials/SpecfunServices.h original implementation]]
     in C from Matthias Seeger.
    """
    if (abs(z) < ERF_CODY_LIMIT1):
        # Phi(z) approx (1 + y R_3(y^2))/2, y = z/sqrt(2)
        return 2.0 * np.exp(logPdfNormal(z)) / (1.0 + (z / M_SQRT2) * _erfRationalHelperR3(0.5 * z * z))
    elif (z < 0.0):
        # Phi(z) approx N(z) Q(-z)/(-z), z<0
        return -z / _erfRationalHelper(-z)
    else:
        t = np.exp(logPdfNormal(z))
        return t / (1.0 - t * _erfRationalHelper(z) / z)