/* fac.c
*
* Factorial function
*
*
*
* SYNOPSIS :
*
* double y , fac ( ) ;
* int i ;
*
* y = fac ( i ) ;
*
*
*
* DESCRIPTION :
*
* Returns factorial of i = 1 * 2 * 3 * . . . * i .
* fac ( 0 ) = 1 . 0 .
*
* Due to machine arithmetic bounds the largest value of
* i accepted is 33 in DEC arithmetic or 170 in IEEE
* arithmetic . Greater values , or negative ones ,
* produce an error message and return MAXNUM .
*
*
*
* ACCURACY :
*
* For i < 34 the values are simply tabulated , and have
* full machine accuracy . If i > 55 , fac ( i ) = gamma ( i + 1 ) ;
* see gamma . c .
*
* Relative error :
* arithmetic domain peak
* IEEE 0 , 170 1 . 4 e - 15
* DEC 0 , 33 1 . 4 e - 17
*
*/
/*
Cephes Math Library Release 2 . 8 : June , 2000
Copyright 1984 , 1987 , 2000 by Stephen L . Moshier
*/
#include "mconf.h"
/* Factorials of integers from 0 through 33 */
#ifdef UNK
static double factbl[] = {
1 .00000000000000000000 E0, 1 .00000000000000000000 E0,
2 .00000000000000000000 E0, 6 .00000000000000000000 E0,
2 .40000000000000000000 E1, 1 .20000000000000000000 E2,
7 .20000000000000000000 E2, 5 .04000000000000000000 E3,
4 .03200000000000000000 E4, 3 .62880000000000000000 E5,
3 .62880000000000000000 E6, 3 .99168000000000000000 E7,
4 .79001600000000000000 E8, 6 .22702080000000000000 E9,
8 .71782912000000000000 E10, 1 .30767436800000000000 E12,
2 .09227898880000000000 E13, 3 .55687428096000000000 E14,
6 .40237370572800000000 E15, 1 .21645100408832000000 E17,
2 .43290200817664000000 E18, 5 .10909421717094400000 E19,
1 .12400072777760768000 E21, 2 .58520167388849766400 E22,
6 .20448401733239439360 E23, 1 .55112100433309859840 E25,
4 .03291461126605635584 E26, 1 .0888869450418352160768 E28,
3 .04888344611713860501504 E29, 8 .841761993739701954543616 E30,
2 .6525285981219105863630848 E32, 8 .22283865417792281772556288 E33,
2 .6313083693369353016721801216 E35, 8 .68331761881188649551819440128 E36};
#define MAXFAC 33
#endif
#ifdef DEC
static unsigned short factbl[] = {
0040200 , 0000000 , 0000000 , 0000000 , 0040200 , 0000000 , 0000000 , 0000000 ,
0040400 , 0000000 , 0000000 , 0000000 , 0040700 , 0000000 , 0000000 , 0000000 ,
0041300 , 0000000 , 0000000 , 0000000 , 0041760 , 0000000 , 0000000 , 0000000 ,
0042464 , 0000000 , 0000000 , 0000000 , 0043235 , 0100000 , 0000000 , 0000000 ,
0044035 , 0100000 , 0000000 , 0000000 , 0044661 , 0030000 , 0000000 , 0000000 ,
0045535 , 0076000 , 0000000 , 0000000 , 0046430 , 0042500 , 0000000 , 0000000 ,
0047344 , 0063740 , 0000000 , 0000000 , 0050271 , 0112146 , 0000000 , 0000000 ,
0051242 , 0060731 , 0040000 , 0000000 , 0052230 , 0035673 , 0126000 , 0000000 ,
0053230 , 0035673 , 0126000 , 0000000 , 0054241 , 0137567 , 0063300 , 0000000 ,
0055265 , 0173546 , 0051630 , 0000000 , 0056330 , 0012711 , 0101504 , 0100000 ,
0057407 , 0006635 , 0171012 , 0150000 , 0060461 , 0040737 , 0046656 , 0030400 ,
0061563 , 0135223 , 0005317 , 0101540 , 0062657 , 0027031 , 0127705 , 0023155 ,
0064003 , 0061223 , 0041723 , 0156322 , 0065115 , 0045006 , 0014773 , 0004410 ,
0066246 , 0146044 , 0172433 , 0173526 , 0067414 , 0136077 , 0027317 , 0114261 ,
0070566 , 0044556 , 0110753 , 0045465 , 0071737 , 0031214 , 0032075 , 0036050 ,
0073121 , 0037543 , 0070371 , 0064146 , 0074312 , 0132550 , 0052561 , 0116443 ,
0075512 , 0132550 , 0052561 , 0116443 , 0076721 , 0005423 , 0114035 , 0025014 };
#define MAXFAC 33
#endif
#ifdef IBMPC
static unsigned short factbl[] = {
0 x0000, 0 x0000, 0 x0000, 0 x3ff0, 0 x0000, 0 x0000, 0 x0000, 0 x3ff0, 0 x0000,
0 x0000, 0 x0000, 0 x4000, 0 x0000, 0 x0000, 0 x0000, 0 x4018, 0 x0000, 0 x0000,
0 x0000, 0 x4038, 0 x0000, 0 x0000, 0 x0000, 0 x405e, 0 x0000, 0 x0000, 0 x8000,
0 x4086, 0 x0000, 0 x0000, 0 xb000, 0 x40b3, 0 x0000, 0 x0000, 0 xb000, 0 x40e3,
0 x0000, 0 x0000, 0 x2600, 0 x4116, 0 x0000, 0 x0000, 0 xaf80, 0 x414b, 0 x0000,
0 x0000, 0 x08a8, 0 x4183, 0 x0000, 0 x0000, 0 x8cfc, 0 x41bc, 0 x0000, 0 xc000,
0 x328c, 0 x41f7, 0 x0000, 0 x2800, 0 x4c3b, 0 x4234, 0 x0000, 0 x7580, 0 x0777,
0 x4273, 0 x0000, 0 x7580, 0 x0777, 0 x42b3, 0 x0000, 0 xecd8, 0 x37ee, 0 x42f4,
0 x0000, 0 xca73, 0 xbeec, 0 x4336, 0 x9000, 0 x3068, 0 x02b9, 0 x437b, 0 x5a00,
0 xbe41, 0 xe1b3, 0 x43c0, 0 xc620, 0 xe9b5, 0 x283b, 0 x4406, 0 xf06c, 0 x6159,
0 x7752, 0 x444e, 0 xa4ce, 0 x35f8, 0 xe5c3, 0 x4495, 0 x7b9a, 0 x687a, 0 x6c52,
0 x44e0, 0 x6121, 0 xc33f, 0 xa940, 0 x4529, 0 x7eeb, 0 x9ea3, 0 xd984, 0 x4574,
0 xf316, 0 xe5d9, 0 x9787, 0 x45c1, 0 x6967, 0 xd23d, 0 xc92d, 0 x460e, 0 xa785,
0 x8687, 0 xe651, 0 x465b, 0 x2d0d, 0 x6e1f, 0 x27ec, 0 x46aa, 0 x33a4, 0 x0aae,
0 x56ad, 0 x46f9, 0 x33a4, 0 x0aae, 0 x56ad, 0 x4749, 0 xa541, 0 x7303, 0 x2162,
0 x479a};
#define MAXFAC 170
#endif
#ifdef MIEEE
static unsigned short factbl[] = {
0 x3ff0, 0 x0000, 0 x0000, 0 x0000, 0 x3ff0, 0 x0000, 0 x0000, 0 x0000, 0 x4000,
0 x0000, 0 x0000, 0 x0000, 0 x4018, 0 x0000, 0 x0000, 0 x0000, 0 x4038, 0 x0000,
0 x0000, 0 x0000, 0 x405e, 0 x0000, 0 x0000, 0 x0000, 0 x4086, 0 x8000, 0 x0000,
0 x0000, 0 x40b3, 0 xb000, 0 x0000, 0 x0000, 0 x40e3, 0 xb000, 0 x0000, 0 x0000,
0 x4116, 0 x2600, 0 x0000, 0 x0000, 0 x414b, 0 xaf80, 0 x0000, 0 x0000, 0 x4183,
0 x08a8, 0 x0000, 0 x0000, 0 x41bc, 0 x8cfc, 0 x0000, 0 x0000, 0 x41f7, 0 x328c,
0 xc000, 0 x0000, 0 x4234, 0 x4c3b, 0 x2800, 0 x0000, 0 x4273, 0 x0777, 0 x7580,
0 x0000, 0 x42b3, 0 x0777, 0 x7580, 0 x0000, 0 x42f4, 0 x37ee, 0 xecd8, 0 x0000,
0 x4336, 0 xbeec, 0 xca73, 0 x0000, 0 x437b, 0 x02b9, 0 x3068, 0 x9000, 0 x43c0,
0 xe1b3, 0 xbe41, 0 x5a00, 0 x4406, 0 x283b, 0 xe9b5, 0 xc620, 0 x444e, 0 x7752,
0 x6159, 0 xf06c, 0 x4495, 0 xe5c3, 0 x35f8, 0 xa4ce, 0 x44e0, 0 x6c52, 0 x687a,
0 x7b9a, 0 x4529, 0 xa940, 0 xc33f, 0 x6121, 0 x4574, 0 xd984, 0 x9ea3, 0 x7eeb,
0 x45c1, 0 x9787, 0 xe5d9, 0 xf316, 0 x460e, 0 xc92d, 0 xd23d, 0 x6967, 0 x465b,
0 xe651, 0 x8687, 0 xa785, 0 x46aa, 0 x27ec, 0 x6e1f, 0 x2d0d, 0 x46f9, 0 x56ad,
0 x0aae, 0 x33a4, 0 x4749, 0 x56ad, 0 x0aae, 0 x33a4, 0 x479a, 0 x2162, 0 x7303,
0 xa541};
#define MAXFAC 170
#endif
#ifdef ANSIPROT
double gamma(double );
#else
double gamma();
#endif
extern double MAXNUM;
double fac(i) int i;
{
double x, f, n;
int j;
if (i < 0 ) {
mtherr("fac" , SING);
return (MAXNUM);
}
if (i > MAXFAC) {
mtherr("fac" , OVERFLOW);
return (MAXNUM);
}
/* Get answer from table for small i. */
if (i < 34 ) {
#ifdef UNK
return (factbl[i]);
#else
return (*(double *)(&factbl[4 * i]));
#endif
}
/* Use gamma function for large i. */
if (i > 55 ) {
x = i + 1 ;
return (gamma(x));
}
/* Compute directly for intermediate i. */
n = 34 .0 ;
f = 34 .0 ;
for (j = 35 ; j <= i; j++) {
n += 1 .0 ;
f *= n;
}
#ifdef UNK
f *= factbl[33 ];
#else
f *= *(double *)(&factbl[4 * 33 ]);
#endif
return (f);
}
Messung V0.5 in Prozent C=96 H=94 G=94