Currently I'm using this C++ routine to approximate the error function
inline double erf(double x)
{
ASSERT(x == x); // check for invalid number
const double a1 = 0.254829592;
const double a2 = -0.284496736;
const double a3 = 1.421413741;
const double a4 = -1.453152027;
const double a5 = 1.061405429;
const double p = 0.3275911;
double t = 1.0 / (1.0 + p * abs(x));
double y = 1.0 - (((((a5 * t + a4) * t) + a3) * t + a2) * t + a1) * t * exp(-x*x);
ASSERT(y > 0.0 && y < 1.0);
return (x < 0.0 ? -y : y);
}
It is based on this post, but I was wondering how to improve its precision. I suspect I need to put in the constants with a better precision (16 digits) and I need more terms. Does anyone how to do this with e.g. a Maple sheet?
The classic C code from Sun Microsystems. It should provide exact results to within 2 ulps for IEEE doubles. You can extract the different rational approximations and the different domains in which they're used if you want to convert to another language.