[gnumeric] GROWTH: simplify.



commit 1abb8f82eb2821add98c9217fc7d2889d8697d7e
Author: Morten Welinder <terra gnome org>
Date:   Sun Jun 13 07:50:37 2010 -0400

    GROWTH: simplify.

 plugins/fn-stat/ChangeLog   |    4 +++
 plugins/fn-stat/functions.c |   46 +++++++++++-------------------------------
 2 files changed, 16 insertions(+), 34 deletions(-)
---
diff --git a/plugins/fn-stat/ChangeLog b/plugins/fn-stat/ChangeLog
index cbf0b2f..ff68b45 100644
--- a/plugins/fn-stat/ChangeLog
+++ b/plugins/fn-stat/ChangeLog
@@ -1,3 +1,7 @@
+2010-06-13  Morten Welinder  <terra gnome org>
+
+	* functions.c (gnumeric_growth): Simplify.
+
 2010-06-11  Morten Welinder  <terra gnome org>
 
 	* functions.c (gnm_reg_data_collect, gnm_reg_data_free): New
diff --git a/plugins/fn-stat/functions.c b/plugins/fn-stat/functions.c
index 3de31e4..8d76346 100644
--- a/plugins/fn-stat/functions.c
+++ b/plugins/fn-stat/functions.c
@@ -3928,13 +3928,11 @@ gnumeric_growth (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
 {
 	gnm_float  *xs = NULL, *ys = NULL, *nxs = NULL;
 	GnmValue    *result = NULL;
-	gboolean affine, err;
+	gboolean affine;
 	int      nx, ny, nnx, i, dim;
 	gnm_float  expres[2];
 	GORegressionResult regres;
 
-	affine = TRUE;
-
 	ys = collect_floats_value (argv[0], ei->pos,
 				   COLLECT_IGNORE_STRINGS |
 				   COLLECT_IGNORE_BOOLS,
@@ -3942,54 +3940,34 @@ gnumeric_growth (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
 	if (result || ny < 1)
 		goto out;
 
-	if (argv[2] != NULL) {
+	if (argv[1] != NULL) {
 		xs = collect_floats_value (argv[1], ei->pos,
 					   COLLECT_IGNORE_STRINGS |
 					   COLLECT_IGNORE_BOOLS,
 					   &nx, &result);
 		if (result)
 			goto out;
+	} else {
+		xs = g_new (gnm_float, ny);
+		for (nx = 0; nx < ny; nx++)
+			xs[nx] = nx + 1;
+	}
 
+	if (argv[2] != NULL) {
 		nxs = collect_floats_value (argv[2], ei->pos,
 					    COLLECT_IGNORE_STRINGS |
 					    COLLECT_IGNORE_BOOLS,
 					    &nnx, &result);
 		if (result)
 			goto out;
-
-		if (argv[3] != NULL) {
-			affine = value_get_as_bool (argv[3], &err);
-			if (err) {
-				result = value_new_error_VALUE (ei->pos);
-				goto out;
-			}
-		}
 	} else {
 		/* @{new_x}'s is assumed to be the same as @{known_x}'s */
-		if (argv[1] != NULL) {
-			xs = collect_floats_value (argv[1], ei->pos,
-						   COLLECT_IGNORE_STRINGS |
-						   COLLECT_IGNORE_BOOLS,
-						   &nx, &result);
-			if (result)
-				goto out;
-
-			nxs = collect_floats_value (argv[1], ei->pos,
-						    COLLECT_IGNORE_STRINGS |
-						    COLLECT_IGNORE_BOOLS,
-						    &nnx, &result);
-			if (result)
-				goto out;
-		} else {
-			xs = g_new (gnm_float, ny);
-			for (nx = 0; nx < ny; nx++)
-				xs[nx] = nx + 1;
-			nxs = g_new (gnm_float, ny);
-			for (nnx = 0; nnx < ny; nnx++)
-				nxs[nnx] = nnx + 1;
-		}
+		nxs = g_memdup (xs, nx * sizeof (gnm_float));
+		nnx = nx;
 	}
 
+	affine = argv[3] ? value_get_as_checked_bool (argv[3]) : TRUE;
+
 	if (nx != ny) {
 		result = value_new_error_NUM (ei->pos);
 		goto out;



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