summaryrefslogtreecommitdiff
path: root/libm/float/pdtrf.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-05-10 00:40:28 +0000
committerEric Andersen <andersen@codepoet.org>2001-05-10 00:40:28 +0000
commit1077fa4d772832f77a677ce7fb7c2d513b959e3f (patch)
tree579bee13fb0b58d2800206366ec2caecbb15f3fc /libm/float/pdtrf.c
parent22358dd7ce7bb49792204b698f01a6f69b9c8e08 (diff)
uClibc now has a math library. muahahahaha!
-Erik
Diffstat (limited to 'libm/float/pdtrf.c')
-rw-r--r--libm/float/pdtrf.c188
1 files changed, 188 insertions, 0 deletions
diff --git a/libm/float/pdtrf.c b/libm/float/pdtrf.c
new file mode 100644
index 000000000..17a05ee13
--- /dev/null
+++ b/libm/float/pdtrf.c
@@ -0,0 +1,188 @@
+/* pdtrf.c
+ *
+ * Poisson distribution
+ *
+ *
+ *
+ * SYNOPSIS:
+ *
+ * int k;
+ * float m, y, pdtrf();
+ *
+ * y = pdtrf( k, m );
+ *
+ *
+ *
+ * DESCRIPTION:
+ *
+ * Returns the sum of the first k terms of the Poisson
+ * distribution:
+ *
+ * k j
+ * -- -m m
+ * > e --
+ * -- j!
+ * j=0
+ *
+ * The terms are not summed directly; instead the incomplete
+ * gamma integral is employed, according to the relation
+ *
+ * y = pdtr( k, m ) = igamc( k+1, m ).
+ *
+ * The arguments must both be positive.
+ *
+ *
+ *
+ * ACCURACY:
+ *
+ * Relative error:
+ * arithmetic domain # trials peak rms
+ * IEEE 0,100 5000 6.9e-5 8.0e-6
+ *
+ */
+ /* pdtrcf()
+ *
+ * Complemented poisson distribution
+ *
+ *
+ *
+ * SYNOPSIS:
+ *
+ * int k;
+ * float m, y, pdtrcf();
+ *
+ * y = pdtrcf( k, m );
+ *
+ *
+ *
+ * DESCRIPTION:
+ *
+ * Returns the sum of the terms k+1 to infinity of the Poisson
+ * distribution:
+ *
+ * inf. j
+ * -- -m m
+ * > e --
+ * -- j!
+ * j=k+1
+ *
+ * The terms are not summed directly; instead the incomplete
+ * gamma integral is employed, according to the formula
+ *
+ * y = pdtrc( k, m ) = igam( k+1, m ).
+ *
+ * The arguments must both be positive.
+ *
+ *
+ *
+ * ACCURACY:
+ *
+ * Relative error:
+ * arithmetic domain # trials peak rms
+ * IEEE 0,100 5000 8.4e-5 1.2e-5
+ *
+ */
+ /* pdtrif()
+ *
+ * Inverse Poisson distribution
+ *
+ *
+ *
+ * SYNOPSIS:
+ *
+ * int k;
+ * float m, y, pdtrf();
+ *
+ * m = pdtrif( k, y );
+ *
+ *
+ *
+ *
+ * DESCRIPTION:
+ *
+ * Finds the Poisson variable x such that the integral
+ * from 0 to x of the Poisson density is equal to the
+ * given probability y.
+ *
+ * This is accomplished using the inverse gamma integral
+ * function and the relation
+ *
+ * m = igami( k+1, y ).
+ *
+ *
+ *
+ *
+ * ACCURACY:
+ *
+ * Relative error:
+ * arithmetic domain # trials peak rms
+ * IEEE 0,100 5000 8.7e-6 1.4e-6
+ *
+ * ERROR MESSAGES:
+ *
+ * message condition value returned
+ * pdtri domain y < 0 or y >= 1 0.0
+ * k < 0
+ *
+ */
+
+/*
+Cephes Math Library Release 2.2: July, 1992
+Copyright 1984, 1987, 1992 by Stephen L. Moshier
+Direct inquiries to 30 Frost Street, Cambridge, MA 02140
+*/
+
+#include <math.h>
+
+#ifdef ANSIC
+float igamf(float, float), igamcf(float, float), igamif(float, float);
+#else
+float igamf(), igamcf(), igamif();
+#endif
+
+
+float pdtrcf( int k, float mm )
+{
+float v, m;
+
+m = mm;
+if( (k < 0) || (m <= 0.0) )
+ {
+ mtherr( "pdtrcf", DOMAIN );
+ return( 0.0 );
+ }
+v = k+1;
+return( igamf( v, m ) );
+}
+
+
+
+float pdtrf( int k, float mm )
+{
+float v, m;
+
+m = mm;
+if( (k < 0) || (m <= 0.0) )
+ {
+ mtherr( "pdtr", DOMAIN );
+ return( 0.0 );
+ }
+v = k+1;
+return( igamcf( v, m ) );
+}
+
+
+float pdtrif( int k, float yy )
+{
+float v, y;
+
+y = yy;
+if( (k < 0) || (y < 0.0) || (y >= 1.0) )
+ {
+ mtherr( "pdtrif", DOMAIN );
+ return( 0.0 );
+ }
+v = k+1;
+v = igamif( v, y );
+return( v );
+}