18 #if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && \
20 #define _USE_MATH_DEFINES
34 double sign(
const double x)
36 return (x > 0) - (x < 0);
69 if ((x == 1.0) || (x == -1.0))
71 r =
sign(x) * INFINITY;
75 double a[4] = {0.886226899, -1.645349621, 0.914624893, -0.140543331};
76 double b[5] = {1.0, -2.118377725, 1.442710462, -0.329097515, 0.012229801};
77 double c[4] = {-1.970840454, -1.62490649, 3.429567803, 1.641345311};
78 double d[3] = {1.0, 3.543889200, 1.637067800};
80 double z =
sign(x) * x;
85 r = z * (((a[3] * x2 + a[2]) * x2 + a[1]) * x2 + a[0]);
86 r /= (((b[4] * x2 + b[3]) * x2 + b[2]) * x2 + b[1]) * x2 + b[0];
90 double y = sqrt(-log((1.0 - z) / 2.0));
91 r = (((c[3] * y + c[2]) * y + c[1]) * y + c[0]);
92 r /= ((d[2] * y + d[1]) * y + d[0]);
100 r -= (erf(r) - z) / ((2.0 / sqrt(M_PI)) * exp(-r * r));
101 r -= (erf(r) - z) / ((2.0 / sqrt(M_PI)) * exp(-r * r));
double erf_inv(const double x)
Inverse error function.
double sign(const double x)
sign function.