12 # if !defined __MINGW32__ || defined __NO_ISOCEXT 14 # define isnan(x) _isnan(x) 17 # define isinf(x) (!_finite(x) && !_isnan(x)) 20 # define finite(x) _finite(x) 25 static double q_gamma(
double,
double,
double);
29 static double p_gamma(
double a,
double x,
double loggamma_a)
32 double result,
term, previous;
34 if (x >= 1 + a)
return 1 - q_gamma(a, x, loggamma_a);
36 result = term = exp(a * log(x) - x - loggamma_a) / a;
37 for (k = 1; k < 1000; k++) {
39 previous = result; result +=
term;
40 if (result == previous)
return result;
42 fprintf(stderr,
"erf.c:%d:p_gamma() could not converge.", __LINE__);
48 static double q_gamma(
double a,
double x,
double loggamma_a)
51 double result, w, temp, previous;
52 double la = 1, lb = 1 + x - a;
54 if (x < 1 + a)
return 1 - p_gamma(a, x, loggamma_a);
55 w = exp(a * log(x) - x - loggamma_a);
57 for (k = 2; k < 1000; k++) {
58 temp = ((k - 1 - a) * (lb - la) + (k + x) * lb) / k;
62 previous = result; result += temp;
63 if (result == previous)
return result;
65 fprintf(stderr,
"erf.c:%d:q_gamma() could not converge.", __LINE__);
69 #define LOG_PI_OVER_2 0.572364942924700087071713675675 74 if (
isnan(x))
return x;
75 return (x>0 ? 1.0 : -1.0);
84 if (
isnan(x))
return x;
85 return (x>0 ? 0.0 : 2.0);
RUBY_EXTERN int finite(double)