[gnumeric] qcauchy: move qcauchy to sf-dpq.c
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] qcauchy: move qcauchy to sf-dpq.c
- Date: Fri, 20 Mar 2015 19:12:05 +0000 (UTC)
commit 5adb17f241eed006e156e03e5148c4b917f44789
Author: Morten Welinder <terra gnome org>
Date: Fri Mar 20 15:10:28 2015 -0400
qcauchy: move qcauchy to sf-dpq.c
plugins/fn-r/extra.c | 27 ---------------------------
src/sf-dpq.c | 41 +++++++++++++++++++++++++++++++++++++++++
src/sf-dpq.h | 6 ++++++
3 files changed, 47 insertions(+), 27 deletions(-)
---
diff --git a/plugins/fn-r/extra.c b/plugins/fn-r/extra.c
index 427cbcb..cd45058 100644
--- a/plugins/fn-r/extra.c
+++ b/plugins/fn-r/extra.c
@@ -6,33 +6,6 @@
#include <sf-gamma.h>
#include "extra.h"
-gnm_float
-qcauchy (gnm_float p, gnm_float location, gnm_float scale,
- gboolean lower_tail, gboolean log_p)
-{
- if (gnm_isnan(p) || gnm_isnan(location) || gnm_isnan(scale))
- return p + location + scale;
-
- if (log_p ? (p > 0) : (p < 0 || p > 1))
- return gnm_nan;
-
- if (scale < 0 || !gnm_finite(scale)) return gnm_nan;
-
- if (log_p) {
- if (p > -1)
- /* The "0" here is important for the p=0 case: */
- lower_tail = !lower_tail, p = 0 - gnm_expm1 (p);
- else
- p = gnm_exp (p);
- }
- if (p > 0.5) {
- p = 1 - p;
- lower_tail = !lower_tail;
- }
- if (lower_tail) scale = -scale;
- return location + scale / gnm_tanpi (p);
-}
-
/* ------------------------------------------------------------------------- */
/* The skew-normal distribution. */
diff --git a/src/sf-dpq.c b/src/sf-dpq.c
index c7374df..41366a3 100644
--- a/src/sf-dpq.c
+++ b/src/sf-dpq.c
@@ -476,3 +476,44 @@ qlnorm (gnm_float p, gnm_float logmean, gnm_float logsd, gboolean lower_tail, gb
return gnm_exp (qnorm (p, logmean, logsd, lower_tail, log_p));
}
+
+/* ------------------------------------------------------------------------ */
+
+/**
+ * qcauchy:
+ * @p: probability
+ * @location: center of distribution
+ * @scale: scale parameter of the distribution
+ * @lower_tail: if %TRUE, the lower tail of the distribution is considered.
+ * @log_p: if %TRUE, @p is given as log probability
+ *
+ * Returns: the observation with cumulative probability @p for the
+ * Cauchy distribution.
+ */
+
+gnm_float
+qcauchy (gnm_float p, gnm_float location, gnm_float scale,
+ gboolean lower_tail, gboolean log_p)
+{
+ if (gnm_isnan(p) || gnm_isnan(location) || gnm_isnan(scale))
+ return p + location + scale;
+
+ if (log_p ? (p > 0) : (p < 0 || p > 1))
+ return gnm_nan;
+
+ if (scale < 0 || !gnm_finite(scale)) return gnm_nan;
+
+ if (log_p) {
+ if (p > -1)
+ /* The "0" here is important for the p=0 case: */
+ lower_tail = !lower_tail, p = 0 - gnm_expm1 (p);
+ else
+ p = gnm_exp (p);
+ }
+ if (p > 0.5) {
+ p = 1 - p;
+ lower_tail = !lower_tail;
+ }
+ if (lower_tail) scale = -scale;
+ return location + scale / gnm_tanpi (p);
+}
diff --git a/src/sf-dpq.h b/src/sf-dpq.h
index 2c0348f..816e87b 100644
--- a/src/sf-dpq.h
+++ b/src/sf-dpq.h
@@ -31,5 +31,11 @@ gnm_float plnorm (gnm_float x, gnm_float logmean, gnm_float logsd, gboolean lowe
gnm_float qlnorm (gnm_float p, gnm_float logmean, gnm_float logsd, gboolean lower_tail, gboolean log_p);
/* ------------------------------------------------------------------------- */
+/* The Cauchy distribution */
+
+gnm_float qcauchy (gnm_float p, gnm_float location, gnm_float scale,
+ gboolean lower_tail, gboolean log_p);
+
+/* ------------------------------------------------------------------------- */
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]