/* rgamma.c
*
* Reciprocal gamma function
*
*
*
* SYNOPSIS :
*
* double x , y , rgamma ( ) ;
*
* y = rgamma ( x ) ;
*
*
*
* DESCRIPTION :
*
* Returns one divided by the gamma function of the argument .
*
* The function is approximated by a Chebyshev expansion in
* the interval [ 0 , 1 ] . Range reduction is by recurrence
* for arguments between - 34 . 034 and + 34 . 84425627277176174 .
* 1 / MAXNUM is returned for positive arguments outside this
* range . For arguments less than - 34 . 034 the cosecant
* reflection formula is applied ; lograrithms are employed
* to avoid unnecessary overflow .
*
* The reciprocal gamma function has no singularities ,
* but overflow and underflow may occur for large arguments .
* These conditions return either MAXNUM or 1 / MAXNUM with
* appropriate sign .
*
* ACCURACY :
*
* Relative error :
* arithmetic domain # trials peak rms
* DEC - 30 , + 30 4000 1 . 2 e - 16 1 . 8 e - 17
* IEEE - 30 , + 30 30000 1 . 1 e - 15 2 . 0 e - 16
* For arguments less than - 34 . 034 the peak error is on the
* order of 5 e - 15 ( DEC ) , excepting overflow or underflow .
*/
/*
Cephes Math Library Release 2 . 8 : June , 2000
Copyright 1985 , 1987 , 2000 by Stephen L . Moshier
*/
#include "mconf.h"
/* Chebyshev coefficients for reciprocal gamma function
* in interval 0 to 1 . Function is 1 / ( x gamma ( x ) ) - 1
*/
#ifdef UNK
static double R[] = {3 .13173458231230000000 E-17 , -6 .70718606477908000000 E-16 ,
2 .20039078172259550000 E-15 , 2 .47691630348254132600 E-13 ,
-6 .60074100411295197440 E-12 , 5 .13850186324226978840 E-11 ,
1 .08965386454418662084 E-9 , -3 .33964630686836942556 E-8 ,
2 .68975996440595483619 E-7 , 2 .96001177518801696639 E-6 ,
-8 .04814124978471142852 E-5 , 4 .16609138709688864714 E-4 ,
5 .06579864028608725080 E-3 , -6 .41925436109158228810 E-2 ,
-4 .98558728684003594785 E-3 , 1 .27546015610523951063 E-1 };
#endif
#ifdef DEC
static unsigned short R[] = {
0022420 , 0066376 , 0176751 , 0071636 , 0123501 , 0051114 , 0042104 , 0131153 ,
0024036 , 0107013 , 0126504 , 0033361 , 0025613 , 0070040 , 0035174 , 0162316 ,
0126750 , 0037060 , 0077775 , 0122202 , 0027541 , 0177143 , 0037675 , 0105150 ,
0030625 , 0141311 , 0075005 , 0115436 , 0132017 , 0067714 , 0125033 , 0014721 ,
0032620 , 0063707 , 0105256 , 0152643 , 0033506 , 0122235 , 0072757 , 0170053 ,
0134650 , 0144041 , 0015617 , 0016143 , 0035332 , 0066125 , 0000776 , 0006215 ,
0036245 , 0177377 , 0137173 , 0131432 , 0137203 , 0073541 , 0055645 , 0141150 ,
0136243 , 0057043 , 0026226 , 0017362 , 0037402 , 0115554 , 0033441 , 0012310 };
#endif
#ifdef IBMPC
static unsigned short R[] = {
0 x2e74, 0 xdfbd, 0 x0d9f, 0 x3c82, 0 x964d, 0 x8888, 0 x2a49, 0 xbcc8,
0 x86de, 0 x75a8, 0 xd1c1, 0 x3ce3, 0 x9c9a, 0 x074f, 0 x6e04, 0 x3d51,
0 xb490, 0 x0fff, 0 x07c6, 0 xbd9d, 0 xb14d, 0 x67f7, 0 x3fcc, 0 x3dcc,
0 xb364, 0 x2f40, 0 xb859, 0 x3e12, 0 x633a, 0 x9543, 0 xedf9, 0 xbe61,
0 xdab4, 0 xf155, 0 x0cf8, 0 x3e92, 0 xfe05, 0 xaebd, 0 xd493, 0 x3ec8,
0 xe38c, 0 x2371, 0 x1904, 0 xbf15, 0 xc192, 0 xa03f, 0 x4d8a, 0 x3f3b,
0 x7663, 0 xf7cf, 0 xbfdf, 0 x3f74, 0 xb84d, 0 x2b74, 0 x6eec, 0 xbfb0,
0 xc3de, 0 x6592, 0 x6bc4, 0 xbf74, 0 x2299, 0 x86e4, 0 x536d, 0 x3fc0};
#endif
#ifdef MIEEE
static unsigned short R[] = {
0 x3c82, 0 x0d9f, 0 xdfbd, 0 x2e74, 0 xbcc8, 0 x2a49, 0 x8888, 0 x964d,
0 x3ce3, 0 xd1c1, 0 x75a8, 0 x86de, 0 x3d51, 0 x6e04, 0 x074f, 0 x9c9a,
0 xbd9d, 0 x07c6, 0 x0fff, 0 xb490, 0 x3dcc, 0 x3fcc, 0 x67f7, 0 xb14d,
0 x3e12, 0 xb859, 0 x2f40, 0 xb364, 0 xbe61, 0 xedf9, 0 x9543, 0 x633a,
0 x3e92, 0 x0cf8, 0 xf155, 0 xdab4, 0 x3ec8, 0 xd493, 0 xaebd, 0 xfe05,
0 xbf15, 0 x1904, 0 x2371, 0 xe38c, 0 x3f3b, 0 x4d8a, 0 xa03f, 0 xc192,
0 x3f74, 0 xbfdf, 0 xf7cf, 0 x7663, 0 xbfb0, 0 x6eec, 0 x2b74, 0 xb84d,
0 xbf74, 0 x6bc4, 0 x6592, 0 xc3de, 0 x3fc0, 0 x536d, 0 x86e4, 0 x2299};
#endif
static char name[] = "rgamma" ;
#ifdef ANSIPROT
extern double chbevl(double , void *, int );
extern double exp(double );
extern double log(double );
extern double sin(double );
extern double lgam(double );
#else
double chbevl(), exp(), log(), sin(), lgam();
#endif
extern double PI, MAXLOG, MAXNUM;
double rgamma(x) double x;
{
double w, y, z;
int sign;
if (x > 34 .84425627277176174 ) {
mtherr(name, UNDERFLOW);
return (1 .0 / MAXNUM);
}
if (x < -34 .034 ) {
w = -x;
z = sin(PI * w);
if (z == 0 .0 )
return (0 .0 );
if (z < 0 .0 ) {
sign = 1 ;
z = -z;
} else
sign = -1 ;
y = log(w * z) - log(PI) + lgam(w);
if (y < -MAXLOG) {
mtherr(name, UNDERFLOW);
return (sign * 1 .0 / MAXNUM);
}
if (y > MAXLOG) {
mtherr(name, OVERFLOW);
return (sign * MAXNUM);
}
return (sign * exp(y));
}
z = 1 .0 ;
w = x;
while (w > 1 .0 ) /* Downward recurrence */
{
w -= 1 .0 ;
z *= w;
}
while (w < 0 .0 ) /* Upward recurrence */
{
z /= w;
w += 1 .0 ;
}
if (w == 0 .0 ) /* Nonpositive integer */
return (0 .0 );
if (w == 1 .0 ) /* Other integer */
return (1 .0 / z);
y = w * (1 .0 + chbevl(4 .0 * w - 2 .0 , R, 16 )) / z;
return (y);
}
Messung V0.5 in Prozent C=96 H=94 G=94
¤ Dauer der Verarbeitung: 0.5 Sekunden
¤
*© Formatika GbR, Deutschland