3 * Inverse of imcomplete beta integral
9 * float a, b, x, y, incbif();
11 * x = incbif( a, b, y );
17 * Given y, the function finds x such that
19 * incbet( a, b, x ) = y.
21 * the routine performs up to 10 Newton iterations to find the
22 * root of incbet(a,b,x) - y = 0.
29 * arithmetic domain domain # trials peak rms
30 * IEEE 0,1 0,100 5000 2.8e-4 8.3e-6
32 * Overflow and larger errors may occur for one of a or b near zero
33 * and the other large.
38 Cephes Math Library Release 2.2: July, 1992
39 Copyright 1984, 1987, 1992 by Stephen L. Moshier
40 Direct inquiries to 30 Frost Street, Cambridge, MA 02140
45 extern float MACHEPF, MINLOGF;
47 #define fabsf(x) ( (x) < 0 ? -(x) : (x) )
50 float incbetf(float, float, float);
51 float ndtrif(float), expf(float), logf(float), sqrtf(float), lgamf(float);
54 float ndtrif(), expf(), logf(), sqrtf(), lgamf();
58 float incbif( float aaa, float bbb, float yyy0 )
60 float incbif( aaa, bbb, yyy0 )
61 double aaa, bbb, yyy0;
64 float aa, bb, yy0, a, b, y0;
65 float d, y, x, x0, x1, lgm, yp, di;
77 /* approximation to inverse function */
98 if( (aa <= 1.0) || (bb <= 1.0) )
104 lgm = (yp * yp - 3.0)* 0.16666666666666667;
105 x0 = 2.0/( 1.0/(2.0*a-1.0) + 1.0/(2.0*b-1.0) );
106 y = yp * sqrtf( x0 + lgm ) / x0
107 - ( 1.0/(2.0*b-1.0) - 1.0/(2.0*a-1.0) )
108 * (lgm + 0.833333333333333333 - 2.0/(3.0*x0));
117 x = a/( a + b * expf(y) );
118 y = incbetf( a, b, x );
120 if( fabsf(yp) < 0.1 )
123 /* Resort to interval halving if not close enough */
128 for( i=0; i<20; i++ )
132 x = di * x1 + (1.0-di) * x0;
133 y = incbetf( a, b, x );
135 if( fabsf(yp) < 1.0e-3 )
156 mtherr( "incbif", UNDERFLOW );
163 lgm = lgamf(a+b) - lgamf(a) - lgamf(b);
165 for( i=0; i<10; i++ )
167 /* compute the function at this point */
170 /* compute the derivative of the function at this point */
171 d = (a - 1.0) * logf(x0) + (b - 1.0) * logf(1.0-x0) + lgm;
178 /* compute the step to the next approximation of x */
194 if( fabsf(d/x0) < 256.0 * MACHEPF )