[gnumeric] qhyper: move this function into sf-dpq.c
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] qhyper: move this function into sf-dpq.c
- Date: Fri, 20 Mar 2015 23:17:50 +0000 (UTC)
commit cc543549910b8244e6beed7a7261077dc3448267
Author: Morten Welinder <terra gnome org>
Date: Fri Mar 20 19:16:47 2015 -0400
qhyper: move this function into sf-dpq.c
src/mathfunc.c | 42 ------------------------------------------
src/sf-dpq.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
src/sf-dpq.h | 5 +++++
3 files changed, 51 insertions(+), 42 deletions(-)
---
diff --git a/src/mathfunc.c b/src/mathfunc.c
index 29cbec2..b53b0d2 100644
--- a/src/mathfunc.c
+++ b/src/mathfunc.c
@@ -4888,48 +4888,6 @@ qf (gnm_float p, gnm_float n1, gnm_float n2, gboolean lower_tail, gboolean log_p
}
-static gnm_float
-phyper1 (gnm_float x, const gnm_float shape[],
- gboolean lower_tail, gboolean log_p)
-{
- return phyper (x, shape[0], shape[1], shape[2], lower_tail, log_p);
-}
-
-gnm_float
-qhyper (gnm_float p, gnm_float NR, gnm_float NB, gnm_float n,
- gboolean lower_tail, gboolean log_p)
-{
- gnm_float y, shape[3];
- gnm_float N = NR + NB;
-
- if (gnm_isnan (p) || gnm_isnan (N) || gnm_isnan (n))
- return p + N + n;
- if(!gnm_finite (p) || !gnm_finite (N) ||
- NR < 0 || NB < 0 || n < 0 || n > N)
- ML_ERR_return_NAN;
-
- shape[0] = NR;
- shape[1] = NB;
- shape[2] = n;
-
- if (N > 2) {
- gnm_float mu = n * NR / N;
- gnm_float sigma =
- gnm_sqrt (NR * NB * n * (N - n) / (N * N * (N - 1)));
- gnm_float sigma_gamma =
- (N - 2 * NR) * (N - 2 * n) / ((N - 2) * N);
-
- /* Cornish-Fisher expansion: */
- gnm_float z = qnorm (p, 0., 1., lower_tail, log_p);
- y = mu + sigma * z + sigma_gamma * (z * z - 1) / 6;
- } else
- y = 0;
-
- return discpfuncinverter (p, shape, lower_tail, log_p,
- MAX (0, n - NB), MIN (n, NR), y,
- phyper1);
-}
-
gnm_float
pbinom2 (gnm_float x0, gnm_float x1, gnm_float n, gnm_float p)
{
diff --git a/src/sf-dpq.c b/src/sf-dpq.c
index 41366a3..1a8ad35 100644
--- a/src/sf-dpq.c
+++ b/src/sf-dpq.c
@@ -517,3 +517,49 @@ qcauchy (gnm_float p, gnm_float location, gnm_float scale,
if (lower_tail) scale = -scale;
return location + scale / gnm_tanpi (p);
}
+
+/* ------------------------------------------------------------------------ */
+
+static gnm_float
+phyper1 (gnm_float x, const gnm_float shape[],
+ gboolean lower_tail, gboolean log_p)
+{
+ return phyper (x, shape[0], shape[1], shape[2], lower_tail, log_p);
+}
+
+gnm_float
+qhyper (gnm_float p, gnm_float NR, gnm_float NB, gnm_float n,
+ gboolean lower_tail, gboolean log_p)
+{
+ gnm_float y, shape[3];
+ gnm_float N = NR + NB;
+
+ if (gnm_isnan (p) || gnm_isnan (N) || gnm_isnan (n))
+ return p + N + n;
+ if(!gnm_finite (p) || !gnm_finite (N) ||
+ NR < 0 || NB < 0 || n < 0 || n > N)
+ return gnm_nan;
+
+ shape[0] = NR;
+ shape[1] = NB;
+ shape[2] = n;
+
+ if (N > 2) {
+ gnm_float mu = n * NR / N;
+ gnm_float sigma =
+ gnm_sqrt (NR * NB * n * (N - n) / (N * N * (N - 1)));
+ gnm_float sigma_gamma =
+ (N - 2 * NR) * (N - 2 * n) / ((N - 2) * N);
+
+ /* Cornish-Fisher expansion: */
+ gnm_float z = qnorm (p, 0., 1., lower_tail, log_p);
+ y = mu + sigma * z + sigma_gamma * (z * z - 1) / 6;
+ } else
+ y = 0;
+
+ return discpfuncinverter (p, shape, lower_tail, log_p,
+ MAX (0, n - NB), MIN (n, NR), y,
+ phyper1);
+}
+
+/* ------------------------------------------------------------------------ */
diff --git a/src/sf-dpq.h b/src/sf-dpq.h
index 816e87b..0a48c08 100644
--- a/src/sf-dpq.h
+++ b/src/sf-dpq.h
@@ -37,5 +37,10 @@ gnm_float qcauchy (gnm_float p, gnm_float location, gnm_float scale,
gboolean lower_tail, gboolean log_p);
/* ------------------------------------------------------------------------- */
+/* Hyper-geometrical distribution. */
+
+gnm_float qhyper (gnm_float p, gnm_float r, gnm_float b, gnm_float n, gboolean lower_tail, gboolean log_p);
+
+/* ------------------------------------------------------------------------- */
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]