OSDN Git Service

uClibc now has a math library. muahahahaha!
[uclinux-h8/uclibc-ng.git] / libm / ldouble / pdtrl.c
1 /*                                                      pdtrl.c
2  *
3  *      Poisson distribution
4  *
5  *
6  *
7  * SYNOPSIS:
8  *
9  * int k;
10  * long double m, y, pdtrl();
11  *
12  * y = pdtrl( k, m );
13  *
14  *
15  *
16  * DESCRIPTION:
17  *
18  * Returns the sum of the first k terms of the Poisson
19  * distribution:
20  *
21  *   k         j
22  *   --   -m  m
23  *   >   e    --
24  *   --       j!
25  *  j=0
26  *
27  * The terms are not summed directly; instead the incomplete
28  * gamma integral is employed, according to the relation
29  *
30  * y = pdtr( k, m ) = igamc( k+1, m ).
31  *
32  * The arguments must both be positive.
33  *
34  *
35  *
36  * ACCURACY:
37  *
38  * See igamc().
39  *
40  */
41 \f/*                                                     pdtrcl()
42  *
43  *      Complemented poisson distribution
44  *
45  *
46  *
47  * SYNOPSIS:
48  *
49  * int k;
50  * long double m, y, pdtrcl();
51  *
52  * y = pdtrcl( k, m );
53  *
54  *
55  *
56  * DESCRIPTION:
57  *
58  * Returns the sum of the terms k+1 to infinity of the Poisson
59  * distribution:
60  *
61  *  inf.       j
62  *   --   -m  m
63  *   >   e    --
64  *   --       j!
65  *  j=k+1
66  *
67  * The terms are not summed directly; instead the incomplete
68  * gamma integral is employed, according to the formula
69  *
70  * y = pdtrc( k, m ) = igam( k+1, m ).
71  *
72  * The arguments must both be positive.
73  *
74  *
75  *
76  * ACCURACY:
77  *
78  * See igam.c.
79  *
80  */
81 \f/*                                                     pdtril()
82  *
83  *      Inverse Poisson distribution
84  *
85  *
86  *
87  * SYNOPSIS:
88  *
89  * int k;
90  * long double m, y, pdtrl();
91  *
92  * m = pdtril( k, y );
93  *
94  *
95  *
96  *
97  * DESCRIPTION:
98  *
99  * Finds the Poisson variable x such that the integral
100  * from 0 to x of the Poisson density is equal to the
101  * given probability y.
102  *
103  * This is accomplished using the inverse gamma integral
104  * function and the relation
105  *
106  *    m = igami( k+1, y ).
107  *
108  *
109  *
110  *
111  * ACCURACY:
112  *
113  * See igami.c.
114  *
115  * ERROR MESSAGES:
116  *
117  *   message         condition      value returned
118  * pdtri domain    y < 0 or y >= 1       0.0
119  *                     k < 0
120  *
121  */
122 \f
123 /*
124 Cephes Math Library Release 2.3:  March, 1995
125 Copyright 1984, 1995 by Stephen L. Moshier
126 */
127
128 #include <math.h>
129 #ifdef ANSIPROT
130 extern long double igaml ( long double, long double );
131 extern long double igamcl ( long double, long double );
132 extern long double igamil ( long double, long double );
133 #else
134 long double igaml(), igamcl(), igamil();
135 #endif
136
137 long double pdtrcl( k, m )
138 int k;
139 long double m;
140 {
141 long double v;
142
143 if( (k < 0) || (m <= 0.0L) )
144         {
145         mtherr( "pdtrcl", DOMAIN );
146         return( 0.0L );
147         }
148 v = k+1;
149 return( igaml( v, m ) );
150 }
151
152
153
154 long double pdtrl( k, m )
155 int k;
156 long double m;
157 {
158 long double v;
159
160 if( (k < 0) || (m <= 0.0L) )
161         {
162         mtherr( "pdtrl", DOMAIN );
163         return( 0.0L );
164         }
165 v = k+1;
166 return( igamcl( v, m ) );
167 }
168
169
170 long double pdtril( k, y )
171 int k;
172 long double y;
173 {
174 long double v;
175
176 if( (k < 0) || (y < 0.0L) || (y >= 1.0L) )
177         {
178         mtherr( "pdtril", DOMAIN );
179         return( 0.0L );
180         }
181 v = k+1;
182 v = igamil( v, y );
183 return( v );
184 }