summaryrefslogtreecommitdiff
path: root/libm/double/igami.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-11-22 14:04:29 +0000
committerEric Andersen <andersen@codepoet.org>2001-11-22 14:04:29 +0000
commit7ce331c01ce6eb7b3f5c715a38a24359da9c6ee2 (patch)
tree3a7e8476e868ae15f4da1b7ce26b2db6f434468c /libm/double/igami.c
parentc117dd5fb183afb1a4790a6f6110d88704be6bf8 (diff)
Totally rework the math library, this time based on the MacOs X
math library (which is itself based on the math lib from FreeBSD). -Erik
Diffstat (limited to 'libm/double/igami.c')
-rw-r--r--libm/double/igami.c187
1 files changed, 0 insertions, 187 deletions
diff --git a/libm/double/igami.c b/libm/double/igami.c
deleted file mode 100644
index e93ba2a14..000000000
--- a/libm/double/igami.c
+++ /dev/null
@@ -1,187 +0,0 @@
-/* igami()
- *
- * Inverse of complemented imcomplete gamma integral
- *
- *
- *
- * SYNOPSIS:
- *
- * double a, x, p, igami();
- *
- * x = igami( a, p );
- *
- * DESCRIPTION:
- *
- * Given p, the function finds x such that
- *
- * igamc( a, x ) = p.
- *
- * Starting with the approximate value
- *
- * 3
- * x = a t
- *
- * where
- *
- * t = 1 - d - ndtri(p) sqrt(d)
- *
- * and
- *
- * d = 1/9a,
- *
- * the routine performs up to 10 Newton iterations to find the
- * root of igamc(a,x) - p = 0.
- *
- * ACCURACY:
- *
- * Tested at random a, p in the intervals indicated.
- *
- * a p Relative error:
- * arithmetic domain domain # trials peak rms
- * IEEE 0.5,100 0,0.5 100000 1.0e-14 1.7e-15
- * IEEE 0.01,0.5 0,0.5 100000 9.0e-14 3.4e-15
- * IEEE 0.5,10000 0,0.5 20000 2.3e-13 3.8e-14
- */
-
-/*
-Cephes Math Library Release 2.8: June, 2000
-Copyright 1984, 1987, 1995, 2000 by Stephen L. Moshier
-*/
-
-#include <math.h>
-
-extern double MACHEP, MAXNUM, MAXLOG, MINLOG;
-#ifdef ANSIPROT
-extern double igamc ( double, double );
-extern double ndtri ( double );
-extern double exp ( double );
-extern double fabs ( double );
-extern double log ( double );
-extern double sqrt ( double );
-extern double lgam ( double );
-#else
-double igamc(), ndtri(), exp(), fabs(), log(), sqrt(), lgam();
-#endif
-
-double igami( a, y0 )
-double a, y0;
-{
-double x0, x1, x, yl, yh, y, d, lgm, dithresh;
-int i, dir;
-
-/* bound the solution */
-x0 = MAXNUM;
-yl = 0;
-x1 = 0;
-yh = 1.0;
-dithresh = 5.0 * MACHEP;
-
-/* approximation to inverse function */
-d = 1.0/(9.0*a);
-y = ( 1.0 - d - ndtri(y0) * sqrt(d) );
-x = a * y * y * y;
-
-lgm = lgam(a);
-
-for( i=0; i<10; i++ )
- {
- if( x > x0 || x < x1 )
- goto ihalve;
- y = igamc(a,x);
- if( y < yl || y > yh )
- goto ihalve;
- if( y < y0 )
- {
- x0 = x;
- yl = y;
- }
- else
- {
- x1 = x;
- yh = y;
- }
-/* compute the derivative of the function at this point */
- d = (a - 1.0) * log(x) - x - lgm;
- if( d < -MAXLOG )
- goto ihalve;
- d = -exp(d);
-/* compute the step to the next approximation of x */
- d = (y - y0)/d;
- if( fabs(d/x) < MACHEP )
- goto done;
- x = x - d;
- }
-
-/* Resort to interval halving if Newton iteration did not converge. */
-ihalve:
-
-d = 0.0625;
-if( x0 == MAXNUM )
- {
- if( x <= 0.0 )
- x = 1.0;
- while( x0 == MAXNUM )
- {
- x = (1.0 + d) * x;
- y = igamc( a, x );
- if( y < y0 )
- {
- x0 = x;
- yl = y;
- break;
- }
- d = d + d;
- }
- }
-d = 0.5;
-dir = 0;
-
-for( i=0; i<400; i++ )
- {
- x = x1 + d * (x0 - x1);
- y = igamc( a, x );
- lgm = (x0 - x1)/(x1 + x0);
- if( fabs(lgm) < dithresh )
- break;
- lgm = (y - y0)/y0;
- if( fabs(lgm) < dithresh )
- break;
- if( x <= 0.0 )
- break;
- if( y >= y0 )
- {
- x1 = x;
- yh = y;
- if( dir < 0 )
- {
- dir = 0;
- d = 0.5;
- }
- else if( dir > 1 )
- d = 0.5 * d + 0.5;
- else
- d = (y0 - yl)/(yh - yl);
- dir += 1;
- }
- else
- {
- x0 = x;
- yl = y;
- if( dir > 0 )
- {
- dir = 0;
- d = 0.5;
- }
- else if( dir < -1 )
- d = 0.5 * d;
- else
- d = (y0 - yl)/(yh - yl);
- dir -= 1;
- }
- }
-if( x == 0.0 )
- mtherr( "igami", UNDERFLOW );
-
-done:
-return( x );
-}