[gnumeric] add MUNIT and RRI



commit 6dc04c476856adbcf014addbb09f19b49cace2a5
Author: Andreas J. Guelzow <aguelzow pyrshep ca>
Date:   Mon Aug 24 23:06:14 2009 -0600

    add MUNIT and RRI
    
    2009-08-25  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* plugin.xml.in: add munit
    	* functions.c (help_munit): new
    	(gnumeric_munit): new
    	(math_functions): add RRI
    
    2009-08-25  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* plugin.xml.in: add rri
    	* functions.c (help_rri): new
    	(gnumeric_rri): new
    	(financial_functions): add RRI
    
    2009-08-25  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* openoffice-read.c (oo_func_map_in): no need to map RRI
    	  and MUNIT
    	* openoffice-write.c (odf_expr_func_handler): we now have
    	  RRI and MUNIT

 NEWS                                  |    3 +-
 plugins/fn-financial/ChangeLog        |    7 ++++++
 plugins/fn-financial/functions.c      |   39 +++++++++++++++++++++++++++++++++
 plugins/fn-financial/plugin.xml.in    |    1 +
 plugins/fn-math/ChangeLog             |    7 ++++++
 plugins/fn-math/functions.c           |   34 ++++++++++++++++++++++++++++
 plugins/fn-math/plugin.xml.in         |    1 +
 plugins/openoffice/ChangeLog          |    7 ++++++
 plugins/openoffice/openoffice-read.c  |    2 -
 plugins/openoffice/openoffice-write.c |    8 +++---
 10 files changed, 102 insertions(+), 7 deletions(-)
---
diff --git a/NEWS b/NEWS
index 49f7704..fa75f05 100644
--- a/NEWS
+++ b/NEWS
@@ -1,7 +1,8 @@
 Gnumeric 1.9.11
 
 Andreas:
-	* Add AVERAGEIF.
+	* Add AVERAGEIF, MUNIT, RRI, SEARCHB, REPLACEB.
+	* Improve import of ODF functions
 
 Morten:
 	* Add GAMMA.
diff --git a/plugins/fn-financial/ChangeLog b/plugins/fn-financial/ChangeLog
index 991e93c..1b2f23b 100644
--- a/plugins/fn-financial/ChangeLog
+++ b/plugins/fn-financial/ChangeLog
@@ -1,3 +1,10 @@
+2009-08-25  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* plugin.xml.in: add rri
+	* functions.c (help_rri): new
+	(gnumeric_rri): new
+	(financial_functions): add RRI
+
 2009-08-24  Andreas J. Guelzow <aguelzow pyrshep ca>
 
 	* functions.c (help_g_duration): add ODF note
diff --git a/plugins/fn-financial/functions.c b/plugins/fn-financial/functions.c
index 3c9385d..b2a7c23 100644
--- a/plugins/fn-financial/functions.c
+++ b/plugins/fn-financial/functions.c
@@ -1275,6 +1275,41 @@ gnumeric_rate (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
 
 /***************************************************************************/
 
+static GnmFuncHelp const help_rri[] = {
+        { GNM_FUNC_HELP_NAME, F_("RRI:equivalent interest rate for an investment increasing in value")},
+        { GNM_FUNC_HELP_ARG, F_("p:number of periods")},
+        { GNM_FUNC_HELP_ARG, F_("pv:present value")},
+        { GNM_FUNC_HELP_ARG, F_("fv:future value")},
+	{ GNM_FUNC_HELP_DESCRIPTION, F_("RRI dtermines an equivalent interest rate for an investment that increases in value. The interest is compounded after each complete period.") },
+	TYPE_HELP,
+	{ GNM_FUNC_HELP_NOTE, F_("Note that @{p} need not be an integer but for fractional value the calculated rate is only approximate.") },
+	{ GNM_FUNC_HELP_ODF, F_("This function is OpenFormula compatible.") },
+        { GNM_FUNC_HELP_EXAMPLES, "=RRI(12,5000,10000)" },
+        { GNM_FUNC_HELP_SEEALSO, "PV,FV,RATE"},
+	{ GNM_FUNC_HELP_END }
+};
+
+
+static GnmValue *
+gnumeric_rri (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
+{
+	gnm_float      per, pv, fv;
+
+	per = value_get_as_float (argv[0]);
+	pv = value_get_as_float (argv[1]);
+	fv = value_get_as_float (argv[2]);
+
+	if (per < 0)
+		return value_new_error_NUM (ei->pos);
+        if (pv == 0. || per == 0.)
+		return value_new_error_DIV0 (ei->pos);
+
+	return value_new_float (gnm_pow(fv/pv,1/per)-1.);
+}
+
+
+/***************************************************************************/
+
 static GnmFuncHelp const help_irr[] = {
         { GNM_FUNC_HELP_NAME, F_("IRR:internal rate of return")},
         { GNM_FUNC_HELP_ARG, F_("values:cash flow")},
@@ -3285,6 +3320,10 @@ GnmFuncDescriptor const financial_functions[] = {
 	  help_rate,	  gnumeric_rate, NULL, NULL, NULL, NULL,
 	  GNM_FUNC_SIMPLE + GNM_FUNC_AUTO_PERCENT,
 	  GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
+	{ "rri", "fff", 
+	  help_rri,	  gnumeric_rri, NULL, NULL, NULL, NULL,
+	  GNM_FUNC_SIMPLE + GNM_FUNC_AUTO_PERCENT,
+	  GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_NO_TESTSUITE },
 	{ "received", "ffff|f", 
 	  help_received,  gnumeric_received, NULL, NULL, NULL, NULL,
 	  GNM_FUNC_SIMPLE + GNM_FUNC_AUTO_MONETARY,
diff --git a/plugins/fn-financial/plugin.xml.in b/plugins/fn-financial/plugin.xml.in
index 9a923a2..fbe41cc 100644
--- a/plugins/fn-financial/plugin.xml.in
+++ b/plugins/fn-financial/plugin.xml.in
@@ -56,6 +56,7 @@
 				<function name="pv"/>
 				<function name="rate"/>
 				<function name="received"/>
+				<function name="rri"/>
 				<function name="sln"/>
 				<function name="syd"/>
 				<function name="tbilleq"/>
diff --git a/plugins/fn-math/ChangeLog b/plugins/fn-math/ChangeLog
index 3176044..9c53376 100644
--- a/plugins/fn-math/ChangeLog
+++ b/plugins/fn-math/ChangeLog
@@ -1,3 +1,10 @@
+2009-08-25  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* plugin.xml.in: add munit
+	* functions.c (help_munit): new
+	(gnumeric_munit): new
+	(math_functions): add RRI
+
 2009-08-20  Morten Welinder  <terra gnome org>
 
 	* functions.c (gnumeric_gammaln): Moved from fn-stat.  Fix domain.
diff --git a/plugins/fn-math/functions.c b/plugins/fn-math/functions.c
index 9afdd61..406a7be 100644
--- a/plugins/fn-math/functions.c
+++ b/plugins/fn-math/functions.c
@@ -2615,6 +2615,36 @@ gnumeric_minverse (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
 
 /***************************************************************************/
 
+static GnmFuncHelp const help_munit[] = {
+        { GNM_FUNC_HELP_NAME, F_("MUNIT:the @{n} by @{n} identity matrix")},
+        { GNM_FUNC_HELP_ARG, F_("n:size of the matrix")},
+	{ GNM_FUNC_HELP_ODF, F_("This function is OpenFormula compatible.")},	
+	{ GNM_FUNC_HELP_SEEALSO, "MMULT,MDETERM,MINVERSE"},
+        { GNM_FUNC_HELP_END}
+};
+
+static GnmValue *
+gnumeric_munit (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
+{
+	gnm_float n = value_get_as_float (argv[0]);
+	gint ni = (int) n, c;
+
+	GnmValue *res;
+
+	if (n <= 0)
+		return value_new_error_NUM (ei->pos);;
+
+	res = value_new_array (ni, ni);
+	for (c = 0; c < ni; ++c) {
+		value_release (res->v_array.vals[c][c]);
+		res->v_array.vals[c][c] =  value_new_int (1);
+	}
+
+	return res;
+}
+
+/***************************************************************************/
+
 static GnmFuncHelp const help_mmult[] = {
         { GNM_FUNC_HELP_NAME, F_("MMULT:the matrix product of @{mat1} and @{mat2}")},
         { GNM_FUNC_HELP_ARG, F_("mat1:a matrix")},
@@ -3090,6 +3120,10 @@ GnmFuncDescriptor const math_functions[] = {
 	{ "mdeterm", "A",  help_mdeterm,
 	  gnumeric_mdeterm, NULL, NULL, NULL, NULL,
 	  GNM_FUNC_RETURNS_NON_SCALAR, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
+	{ "munit","f",      help_munit,
+	  gnumeric_munit, NULL, NULL, NULL, NULL,
+	  GNM_FUNC_RETURNS_NON_SCALAR, GNM_FUNC_IMPL_STATUS_COMPLETE, 
+	  GNM_FUNC_TEST_STATUS_NO_TESTSUITE },
 #if 0
 	{ "logmdeterm", "A|si", 
 	  help_logmdeterm, gnumeric_logmdeterm, NULL, NULL, NULL },
diff --git a/plugins/fn-math/plugin.xml.in b/plugins/fn-math/plugin.xml.in
index f4b0623..e42471f 100644
--- a/plugins/fn-math/plugin.xml.in
+++ b/plugins/fn-math/plugin.xml.in
@@ -61,6 +61,7 @@
 				<function name="mod"/>
 				<function name="mround"/>
 				<function name="multinomial"/>
+				<function name="munit"/>
 				<function name="odd"/>
 				<function name="pi"/>
 				<function name="power"/>
diff --git a/plugins/openoffice/ChangeLog b/plugins/openoffice/ChangeLog
index d86a1cc..b11fa35 100644
--- a/plugins/openoffice/ChangeLog
+++ b/plugins/openoffice/ChangeLog
@@ -1,3 +1,10 @@
+2009-08-25  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* openoffice-read.c (oo_func_map_in): no need to map RRI
+	  and MUNIT
+	* openoffice-write.c (odf_expr_func_handler): we now have
+	  RRI and MUNIT
+	
 2009-08-24  Andreas J. Guelzow <aguelzow pyrshep ca>
 
 	* openoffice-read.c (oo_func_map_in): map PDURATION to
diff --git a/plugins/openoffice/openoffice-read.c b/plugins/openoffice/openoffice-read.c
index ab7361f..9016450 100644
--- a/plugins/openoffice/openoffice-read.c
+++ b/plugins/openoffice/openoffice-read.c
@@ -4616,9 +4616,7 @@ oo_func_map_in (GnmConventions const *convs, Workbook *scope,
 		{ "IFNA","ODF.IFNA" },
 		{ "ISFORMULA","ODF.ISFORMULA" },
 		{ "MULTIPLE.OPERATIONS","ODF.MULTIPLE.OPERATIONS" },
-		{ "MUNIT","ODF.MUNIT" },
 		{ "NUMBERVALUE","ODF.NUMBERVALUE" },
-		{ "RRI","ODF.RRI" },
 		{ "SHEET","ODF.SHEET" },
 		{ "SHEETS","ODF.SHEETS" },
 		{ "SUMIFS","ODF.SUMIFS" },
diff --git a/plugins/openoffice/openoffice-write.c b/plugins/openoffice/openoffice-write.c
index d230287..53c42fe 100644
--- a/plugins/openoffice/openoffice-write.c
+++ b/plugins/openoffice/openoffice-write.c
@@ -1706,7 +1706,7 @@ odf_expr_func_handler (GnmConventionsOut *out, GnmExprFunction const *func)
 		{ "GAMMADIST","GAMMADIST" },
 		{ "GAMMAINV","GAMMAINV" },
 		{ "GAMMALN","GAMMALN" },
-		/* { "GAUSS","GAUSS" },  not implemented */
+		/* { "GAUSS","GAUSS" },  converted to ERF on import */
 		{ "GCD","GCD" },
 		{ "GEOMEAN","GEOMEAN" },
 		{ "GESTEP","GESTEP" },
@@ -1812,7 +1812,7 @@ odf_expr_func_handler (GnmConventionsOut *out, GnmExprFunction const *func)
 		{ "MROUND","MROUND" },
 		{ "MULTINOMIAL","MULTINOMIAL" },
 		/* { "MULTIPLE.OPERATIONS","MULTIPLE.OPERATIONS" },  not implemented */
-		/* { "MUNIT","MUNIT" },  not implemented */
+		{ "MUNIT","MUNIT" },
 		{ "N","N" },
 		{ "NA","NA" },
 		{ "NEGBINOMDIST","NEGBINOMDIST" },
@@ -1841,7 +1841,7 @@ odf_expr_func_handler (GnmConventionsOut *out, GnmExprFunction const *func)
 		{ "PERCENTRANK","PERCENTRANK" },
 		{ "PERMUT","PERMUT" },
 		{ "PERMUTATIONA","PERMUTATIONA" },
-		/* { "PHI","PHI" },  not implemented */
+		/* { "PHI","PHI" },  converted to NORMDIST on import */
 		{ "PI","PI" },
 		{ "PMT","PMT" },
 		{ "POISSON","POISSON" },
@@ -1873,7 +1873,7 @@ odf_expr_func_handler (GnmConventionsOut *out, GnmExprFunction const *func)
 		{ "ROUNDUP","ROUNDUP" },
 		{ "ROW","ROW" },
 		{ "ROWS","ROWS" },
-		/* { "RRI","RRI" },  not implemented */
+		{ "RRI","RRI" },
 		{ "RSQ","RSQ" },
 		{ "SEARCH","SEARCH" },
 		{ "SEARCHB","SEARCHB" },



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]