1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.math.special;
17
18 import java.io.Serializable;
19
20 import org.apache.commons.math.MathException;
21
22 /**
23 * This is a utility class that provides computation methods related to the
24 * error functions.
25 *
26 * @version $Revision: 155427 $ $Date: 2005-02-26 06:11:52 -0700 (Sat, 26 Feb 2005) $
27 */
28 public class Erf implements Serializable {
29
30 /**
31 * Default constructor. Prohibit instantiation.
32 */
33 private Erf() {
34 super();
35 }
36
37 /**
38 * Returns the error function erf(x).
39 *
40 * The implementation of this method is based on:
41 * <ul>
42 * <li>
43 * <a href="http://mathworld.wolfram.com/Erf.html">
44 * Erf</a>, equation (3).</li>
45 * </ul>
46 *
47 * @param x the value.
48 * @return the error function erf(x)
49 * @throws MathException if the algorithm fails to converge.
50 */
51 public static double erf(double x) throws MathException {
52 double ret = Gamma.regularizedGammaP(0.5, x * x, 1.0e-15, 10000);
53 if (x < 0) {
54 ret = -ret;
55 }
56 return ret;
57 }
58 }