Accord.Math.Normal.HighAccuracyFunction C# (CSharp) Method

HighAccuracyFunction() public static method

High-accuracy Normal cumulative distribution function.

The following formula provide probabilities with an absolute error less than 8e-16.

References: - George Marsaglia, Evaluating the Normal Distribution, 2004. Available in: http://www.jstatsoft.org/v11/a05/paper

public static HighAccuracyFunction ( double x ) : double
x double
return double
        public static double HighAccuracyFunction(double x)
        {
            double sum = x;
            double term = 0;

            double nextTerm = x;
            double pwr = x * x;
            double i = 1;

            // Iterate until adding next terms doesn't produce
            // any change within the current numerical accuracy.

            while (sum != term)
            {
                term = sum;

                // Next term
                nextTerm *= pwr / (i += 2);

                sum += nextTerm;
            }

            return 0.5 + sum * Math.Exp(-0.5 * pwr - 0.5 * Constants.Log2PI);
        }