inline long double ibeta(long double a, long double b, long double x) { #ifdef BOOST_MSVC return incbet((double)a, (double)b, (double)x); #else return incbetl(a, b); #endif }
double fdtrc(double a, double b, double x) { double w; if ((a <= 0.0) || (b <= 0.0) || (x < 0.0)) { mtherr("fdtrc", DOMAIN); return CEPHES_NAN; } w = b / (b + a * x); return incbet(0.5 * b, 0.5 * a, w); }
double fdtr(double a, double b, double x) { double w; if ((a <= 0.0) || (b <= 0.0) || (x < 0.0)) { mtherr("fdtr", DOMAIN); return CEPHES_NAN; } w = a * x; w = w / (b + w); return incbet(0.5 * a, 0.5 * b, w); }
double fdtri(double a, double b, double y) { double w, x; if ((a <= 0.0) || (b <= 0.0) || (y <= 0.0) || (y > 1.0)) { mtherr("fdtri", DOMAIN); return CEPHES_NAN; } y = 1.0 - y; /* Compute probability for x = 0.5. */ w = incbet(0.5 * b, 0.5 * a, 0.5); /* If that is greater than y, then the solution w < .5. * Otherwise, solve at 1-y to remove cancellation in (b - b*w). */ if (w > y || y < 0.001) { w = incbi(0.5 * b, 0.5 * a, y); x = (b - b * w) / (a * w); } else { w = incbi(0.5 * a, 0.5 * b, 1.0 - y); x = b * w / (a * (1.0 - w)); } return x; }
double btdtr( double a, double b, double x ) { return( incbet( a, b, x ) ); }
inline double ibeta(double a, double b, double x) { return incbet(a, b, x); }
double stdtr (double rk, double t) { double x, z, f, tz, p, xsqk; int k, j, is_int; if (rk <= 0) { mtherr("stdtr", CEPHES_DOMAIN); return 0.0; } else { k = (int) rk; is_int = (rk - k) == 0.0; } if (t == 0) { return 0.5; } if (t < -2.0) { z = rk / (rk + t * t); p = 0.5 * incbet(0.5*rk, 0.5, z); return p; } if (is_int) { /* integer df */ /* compute integral from -t to +t */ if (t < 0) { x = -t; } else { x = t; } z = 1.0 + (x * x)/rk; /* test if k is odd or even */ if ((k & 1) != 0) { /* computation for odd k */ xsqk = x/sqrt(rk); p = atan(xsqk); if (k > 1) { f = 1.0; tz = 1.0; j = 3; while ((j <= (k-2)) && ((tz/f) > MACHEP)) { tz *= (j - 1)/(z * j); f += tz; j += 2; } p += f * xsqk/z; } p *= 2.0/PI; } else { /* computation for even k */ f = 1.0; tz = 1.0; j = 2; while ((j <= (k-2)) && ((tz/f) > MACHEP)) { tz *= (j - 1)/(z * j); f += tz; j += 2; } p = f * x/sqrt(z*rk); } /* common exit */ if (t < 0) { p = -p; /* note destruction of relative accuracy */ } p = 0.5 + 0.5 * p; } else { /* non-integer df */ z = rk / (rk + t * t); p = 0.5 * incbet(0.5*rk, 0.5, z); if (t > 0) { p = 1-p; } } return p; }