Robust implementations of 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 cdfNormal(z):
    """
    Robust implementations of 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 0.5 * (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 np.exp(logPdfNormal(z)) * _erfRationalHelper(-z) / (-z)
    else:
        return 1.0 - np.exp(logPdfNormal(z)) * _erfRationalHelper(z) / z