double stdtri (double rk, double p) { double t, z; int rflg; if (rk <= 0 || p <= 0.0 || p >= 1.0) { mtherr("stdtri", CEPHES_DOMAIN); return 0.0; } if (p > 0.25 && p < 0.75) { if (p == 0.5) { return 0.0; } z = 1.0 - 2.0 * p; z = incbi(0.5, 0.5*rk, fabs(z)); t = sqrt(rk * z/(1.0-z)); if (p < 0.5) { t = -t; } return t; } rflg = -1; if (p >= 0.5) { p = 1.0 - p; rflg = 1; } z = incbi(0.5*rk, 0.5, 2.0*p); if (MAXNUM * z < rk) { return rflg * MAXNUM; } t = sqrt(rk/z - rk); return rflg * t; }
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; }