OSDN Git Service

Add MS7619SE
[uclinux-h8/uClinux-dist.git] / lib / libm / facf.c
1 /*                                                      facf.c
2  *
3  *      Factorial function
4  *
5  *
6  *
7  * SYNOPSIS:
8  *
9  * float y, facf();
10  * int i;
11  *
12  * y = facf( i );
13  *
14  *
15  *
16  * DESCRIPTION:
17  *
18  * Returns factorial of i  =  1 * 2 * 3 * ... * i.
19  * fac(0) = 1.0.
20  *
21  * Due to machine arithmetic bounds the largest value of
22  * i accepted is 33 in single precision arithmetic.
23  * Greater values, or negative ones,
24  * produce an error message and return MAXNUM.
25  *
26  *
27  *
28  * ACCURACY:
29  *
30  * For i < 34 the values are simply tabulated, and have
31  * full machine accuracy.
32  *
33  */
34 \f
35 /*
36 Cephes Math Library Release 2.0:  April, 1987
37 Copyright 1984, 1987 by Stephen L. Moshier
38 Direct inquiries to 30 Frost Street, Cambridge, MA 02140
39 */
40
41 #include "mconf.h"
42
43 /* Factorials of integers from 0 through 33 */
44 static double factbl[] = {
45   1.00000000000000000000E0,
46   1.00000000000000000000E0,
47   2.00000000000000000000E0,
48   6.00000000000000000000E0,
49   2.40000000000000000000E1,
50   1.20000000000000000000E2,
51   7.20000000000000000000E2,
52   5.04000000000000000000E3,
53   4.03200000000000000000E4,
54   3.62880000000000000000E5,
55   3.62880000000000000000E6,
56   3.99168000000000000000E7,
57   4.79001600000000000000E8,
58   6.22702080000000000000E9,
59   8.71782912000000000000E10,
60   1.30767436800000000000E12,
61   2.09227898880000000000E13,
62   3.55687428096000000000E14,
63   6.40237370572800000000E15,
64   1.21645100408832000000E17,
65   2.43290200817664000000E18,
66   5.10909421717094400000E19,
67   1.12400072777760768000E21,
68   2.58520167388849766400E22,
69   6.20448401733239439360E23,
70   1.55112100433309859840E25,
71   4.03291461126605635584E26,
72   1.0888869450418352160768E28,
73   3.04888344611713860501504E29,
74   8.841761993739701954543616E30,
75   2.6525285981219105863630848E32,
76   8.22283865417792281772556288E33,
77   2.6313083693369353016721801216E35,
78   8.68331761881188649551819440128E36
79 };
80 #define MAXFACF 33
81
82 extern double MAXNUMF;
83
84 #ifdef ANSIC
85 float facf( int i )
86 #else
87 float facf(i)
88 int i;
89 #endif
90 {
91
92 if( i < 0 )
93         {
94         mtherr( "facf", SING );
95         return( MAXNUMF );
96         }
97
98 if( i > MAXFACF )
99         {
100         mtherr( "facf", OVERFLOW );
101         return( MAXNUMF );
102         }
103
104 /* Get answer from table for small i. */
105 return( factbl[i] );
106 }