[gnumeric] Add BINOM.DIST.RANGE (equivalent to the ODF function B).
- From: Andreas J. Guelzow <guelzow src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnumeric] Add BINOM.DIST.RANGE (equivalent to the ODF function B).
- Date: Sat, 24 Oct 2009 20:36:21 +0000 (UTC)
commit 21219fa12720988633d826c2748f7d27974c7c99
Author: Andreas J. Guelzow <aguelzow pyrshep ca>
Date: Sat Oct 24 14:35:07 2009 -0600
Add BINOM.DIST.RANGE (equivalent to the ODF function B).
2009-10-24 Andreas J. Guelzow <aguelzow pyrshep ca>
* functions.c (help_binom_dist-range): new
(gnumeric_binom_dist_range): new
(stat_functions): add BINOM.DIST.RANGE
* plugin.xml.in: add BINOM.DIST.RANGE
2009-10-24 Andreas J. Guelzow <aguelzow pyrshep ca>
* openoffice-read.c (oo_func_map_in): we now have BINOM.DIST.RANGE
(equivalent to the ODF function B)
* openoffice-write.c (odf_expr_func_handler): ditto
NEWS | 1 +
plugins/fn-stat/ChangeLog | 7 +++++
plugins/fn-stat/functions.c | 49 +++++++++++++++++++++++++++++++++
plugins/fn-stat/plugin.xml.in | 1 +
plugins/openoffice/ChangeLog | 6 ++++
plugins/openoffice/openoffice-read.c | 3 +-
plugins/openoffice/openoffice-write.c | 2 +-
7 files changed, 66 insertions(+), 3 deletions(-)
---
diff --git a/NEWS b/NEWS
index efcdd87..4abca42 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,7 @@ Andreas:
* A few functions from the christian liturgical calendar.
* Add ODF compatibility functions DAYS, ISFORMULA and NUMBERVALUE.
* Work around OpenOffice.org saving function names in lowercase.
+ * Add BINOM.DIST.RANGE (equivalent to the ODF function B).
Jody:
* First steps towards a turnkey win32 build.
diff --git a/plugins/fn-stat/ChangeLog b/plugins/fn-stat/ChangeLog
index f4c4a51..b6d3ff3 100644
--- a/plugins/fn-stat/ChangeLog
+++ b/plugins/fn-stat/ChangeLog
@@ -1,3 +1,10 @@
+2009-10-24 Andreas J. Guelzow <aguelzow pyrshep ca>
+
+ * functions.c (help_binom_dist-range): new
+ (gnumeric_binom_dist_range): new
+ (stat_functions): add BINOM.DIST.RANGE
+ * plugin.xml.in: add BINOM.DIST.RANGE
+
2009-10-11 Morten Welinder <terra gnome org>
* Release 1.9.14
diff --git a/plugins/fn-stat/functions.c b/plugins/fn-stat/functions.c
index e053804..39b4297 100644
--- a/plugins/fn-stat/functions.c
+++ b/plugins/fn-stat/functions.c
@@ -1427,6 +1427,52 @@ gnumeric_binomdist (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
/***************************************************************************/
+static GnmFuncHelp const help_binom_dist_range[] = {
+ { GNM_FUNC_HELP_NAME, F_("BINOM.DIST.RANGE:probability of the binomial distribution over an interval")},
+ { GNM_FUNC_HELP_ARG, F_("n:number of successes")},
+ { GNM_FUNC_HELP_ARG, F_("trials:number of trials")},
+ { GNM_FUNC_HELP_ARG, F_("p:probability of success in each trial")},
+ { GNM_FUNC_HELP_ARG, F_("start:start of the interval")},
+ { GNM_FUNC_HELP_ARG, F_("end:start of the interval, defaults to @{start}")},
+ { GNM_FUNC_HELP_NOTE, F_("If @{start}, @{end} or @{trials} are non-integer they are truncated.") },
+ { GNM_FUNC_HELP_NOTE, F_("If @{trials} < 0 this function returns a #NUM! error.") },
+ { GNM_FUNC_HELP_NOTE, F_("If @{p} < 0 or @{p} > 1 this function returns a #NUM! error.")},
+ { GNM_FUNC_HELP_NOTE, F_("If @{start} > @{end} this function returns 0.")},
+ { GNM_FUNC_HELP_ODF, F_("This function is the OpenFormula function B") },
+ { GNM_FUNC_HELP_EXAMPLES, "=BINOM.DIST.RANGE(5,0.8,3,4)" },
+ { GNM_FUNC_HELP_SEEALSO, "BINOMDIST,R.PBINOM"},
+ { GNM_FUNC_HELP_END }
+};
+
+static GnmValue *
+gnumeric_binom_dist_range (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
+{
+ int trials = value_get_as_int (argv[0]);
+ gnm_float p = value_get_as_float (argv[1]);
+ int start = value_get_as_int (argv[2]);
+ int end = argv[3] ? value_get_as_int (argv[3]) : start;
+
+ if (trials < 0 || p < 0 || p > 1)
+ return value_new_error_NUM (ei->pos);
+
+ if (start > trials || end < 0 || start > end)
+ return value_new_float (0.);
+
+ if (start == 0 && end == trials)
+ return value_new_float (1.);
+
+ if (start != end) {
+ if (start == 0)
+ return value_new_float (pbinom (end, trials, p, TRUE, FALSE));
+ else if (end == trials)
+ return value_new_float (pbinom (start, trials, p, FALSE, FALSE));
+ else
+ return value_new_float (pbinom (end, trials, p, TRUE, FALSE) - pbinom (start - 1, trials, p, TRUE, FALSE));
+ } else
+ return value_new_float (dbinom (start, trials, p, FALSE));
+}
+
+/***************************************************************************/
static GnmFuncHelp const help_cauchy[] = {
{ GNM_FUNC_HELP_NAME, F_("CAUCHY:(cumulative) probability density function of the Cauchy, "
"Lorentz or Breit-Wigner distribution")},
@@ -4842,6 +4888,9 @@ GnmFuncDescriptor const stat_functions[] = {
{ "binomdist", "fffb",
help_binomdist, gnumeric_binomdist, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
+ { "binom.dist.range", "fff|f",
+ help_binom_dist_range, gnumeric_binom_dist_range, NULL, NULL, NULL, NULL,
+ GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC, GNM_FUNC_TEST_STATUS_NO_TESTSUITE },
{ "cauchy", "ffb", help_cauchy,
gnumeric_cauchy, NULL, NULL, NULL, NULL,
diff --git a/plugins/fn-stat/plugin.xml.in b/plugins/fn-stat/plugin.xml.in
index d46ea1a..2e5e909 100644
--- a/plugins/fn-stat/plugin.xml.in
+++ b/plugins/fn-stat/plugin.xml.in
@@ -17,6 +17,7 @@
<function name="bernoulli"/>
<function name="betadist"/>
<function name="betainv"/>
+ <function name="binom.dist.range"/>
<function name="binomdist"/>
<function name="cauchy"/>
<function name="chidist"/>
diff --git a/plugins/openoffice/ChangeLog b/plugins/openoffice/ChangeLog
index 47579ae..71fb9a8 100644
--- a/plugins/openoffice/ChangeLog
+++ b/plugins/openoffice/ChangeLog
@@ -1,5 +1,11 @@
2009-10-24 Andreas J. Guelzow <aguelzow pyrshep ca>
+ * openoffice-read.c (oo_func_map_in): we now have BINOM.DIST.RANGE
+ (equivalent to the ODF function B)
+ * openoffice-write.c (odf_expr_func_handler): ditto
+
+2009-10-24 Andreas J. Guelzow <aguelzow pyrshep ca>
+
* openoffice-read.c (oo_func_map_in): we now have NUMBERVALUE
* openoffice-write.c (odf_expr_func_handler): ditto
diff --git a/plugins/openoffice/openoffice-read.c b/plugins/openoffice/openoffice-read.c
index f067f13..fbcca24 100644
--- a/plugins/openoffice/openoffice-read.c
+++ b/plugins/openoffice/openoffice-read.c
@@ -4656,7 +4656,6 @@ oo_func_map_in (GnmConventions const *convs, Workbook *scope,
/* where we do not have a function with the same name */
{ "AVERAGEIFS","ODF.AVERAGEIFS" },
- { "B","ODF.B" },
{ "COUNTIFS","ODF.COUNTIFS" },
{ "DDE","ODF.DDE" },
{ "IFNA","ODF.IFNA" },
@@ -4668,6 +4667,7 @@ oo_func_map_in (GnmConventions const *convs, Workbook *scope,
/* The following is a complete list of the functions defined in ODF OpenFormula draft 20090508 */
/* We should determine whether any mapping is needed. */
+ { "B","BINOM.DIST.RANGE" },
{ "CEILING","ODF.CEILING" }, /* see handler */
{ "CHISQINV","R.QCHISQ" },
{ "CHISQDIST","ODF.CHISQDIST" }, /* see handler */
@@ -4709,7 +4709,6 @@ oo_func_map_in (GnmConventions const *convs, Workbook *scope,
/* { "AVERAGEA","AVERAGEA" }, */
/* { "AVERAGEIF","AVERAGEIF" }, */
/* { "AVERAGEIFS","AVERAGEIFS" }, */
-/* { "B","B" }, */
/* { "BASE","BASE" }, */
/* { "BESSELI","BESSELI" }, */
/* { "BESSELJ","BESSELJ" }, */
diff --git a/plugins/openoffice/openoffice-write.c b/plugins/openoffice/openoffice-write.c
index 40566b7..ce26edc 100644
--- a/plugins/openoffice/openoffice-write.c
+++ b/plugins/openoffice/openoffice-write.c
@@ -1602,7 +1602,7 @@ odf_expr_func_handler (GnmConventionsOut *out, GnmExprFunction const *func)
{ "AVERAGEA","AVERAGEA" },
{ "AVERAGEIF","AVERAGEIF" },
/* { "ODF.AVERAGEIFS","AVERAGEIFS" }, not implemented */
- /* { "ODF.B","B" }, not implemented */
+ { "BINOM.DIST.RANGE","B" },
{ "BASE","BASE" },
{ "BESSELI","BESSELI" },
{ "BESSELJ","BESSELJ" },
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]