/** * @param a double value * @return The area under the Gaussian probability density * function, integrated from minus infinity to x: * @throws ArithmeticException */ static public double normal(double a) throws ArithmeticException { double x, y, z; x = a * SQRTH; z = Math.abs(x); if (z < SQRTH) { y = 0.5 + 0.5 * erf(x); } else { y = 0.5 * erfc(z); if (x > 0) { y = 1.0 - y; } } return y; }
/** * @param x double value * @return The Error function * <p/> * <FONT size=2> * Converted to Java from<BR> * Cephes Math Library Release 2.2: July, 1992<BR> * Copyright 1984, 1987, 1989, 1992 by Stephen L. Moshier<BR> * Direct inquiries to 30 Frost Street, Cambridge, MA 02140<BR> * @throws ArithmeticException */ static public double erf(double x) throws ArithmeticException { double y, z; double T[] = {9.60497373987051638749E0, 9.00260197203842689217E1, 2.23200534594684319226E3, 7.00332514112805075473E3, 5.55923013010394962768E4}; double U[] = { //1.00000000000000000000E0, 3.35617141647503099647E1, 5.21357949780152679795E2, 4.59432382970980127987E3, 2.26290000613890934246E4, 4.92673942608635921086E4 }; if (Math.abs(x) > 1.0) { return (1.0 - erfc(x)); } z = x * x; y = x * polevl(z, T, 4) / p1evl(z, U, 5); return y; }