27static const RealType rel_error = 1E-12;
31static RealType erfc(RealType x);
33static RealType erf(RealType x)
38 static const RealType two_sqrtpi = 1.128379167095512574;
42 RealType sum = x, term = x, xsqr = x * x;
46 sum -= term / (2 * j + 1);
49 sum += term / (2 * j + 1);
51 }
while (fabs(term) / sum > rel_error);
52 return two_sqrtpi * sum;
55static RealType erfc(RealType x)
62 static const RealType one_sqrtpi = 0.564189583547756287;
68 return 2.0 - erfc(-x);
70 RealType a = 1, b = x;
71 RealType c = x, d = x * x + 0.5;
72 RealType q1, q2 = b / d;
84 }
while (fabs(q1 - q2) / q2 > rel_error);
85 return one_sqrtpi * exp(-x * x) * q2;