[gnumeric] simplify the expression created for general ODF ceiling



commit ca60dd411361416efde23036229f0a3322ab3991
Author: Andreas J. Guelzow <aguelzow pyrshep ca>
Date:   Fri Jun 19 02:10:02 2009 -0600

    simplify the expression created for general ODF ceiling
    
    2009-06-19 Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* openoffice-read.c (odf_func_ceiling_handler): fix logic

 plugins/openoffice/ChangeLog         |    4 ++
 plugins/openoffice/openoffice-read.c |   56 ++++++++++++++++++----------------
 2 files changed, 34 insertions(+), 26 deletions(-)
---
diff --git a/plugins/openoffice/ChangeLog b/plugins/openoffice/ChangeLog
index 6fd0581..9bc502d 100644
--- a/plugins/openoffice/ChangeLog
+++ b/plugins/openoffice/ChangeLog
@@ -1,5 +1,9 @@
 2009-06-19 Andreas J. Guelzow <aguelzow pyrshep ca>
 
+	* openoffice-read.c (odf_func_ceiling_handler): fix logic
+	
+2009-06-19 Andreas J. Guelzow <aguelzow pyrshep ca>
+
 	* openoffice-read.c (odf_func_ceiling_handler): new
 	(oo_func_map_in): hook up the above handler
 	* openoffice-write.c (odf_func_ceiling_handler): new
diff --git a/plugins/openoffice/openoffice-read.c b/plugins/openoffice/openoffice-read.c
index 37f49c5..56264ee 100644
--- a/plugins/openoffice/openoffice-read.c
+++ b/plugins/openoffice/openoffice-read.c
@@ -3612,34 +3612,37 @@ odf_func_ceiling_handler (GnmConventions const *convs, Workbook *scope, GnmExprL
 		GnmExpr const *expr_mode_one;
 		GnmExpr const *expr_if;
 		GnmExpr const *expr_mode;
-		GnmExpr const *expr_sign;
+		GnmExpr const *expr_x = g_slist_nth_data ((GSList *) args, 0);
+		GnmExpr const *expr_sig = g_slist_nth_data ((GSList *) args, 1);
+		
 		GnmFunc  *fd_ceiling = gnm_func_lookup_or_add_placeholder ("CEILING", scope, FALSE);
-		GnmFunc  *fd_abs = gnm_func_lookup_or_add_placeholder ("ABS", scope, FALSE);
-		GnmFunc  *fd_sign = gnm_func_lookup_or_add_placeholder ("SIGN", scope, FALSE);
+		GnmFunc  *fd_floor = gnm_func_lookup_or_add_placeholder ("FLOOR", scope, FALSE);
 		GnmFunc  *fd_if = gnm_func_lookup_or_add_placeholder ("IF", scope, FALSE);
 		
-		expr_sign = gnm_expr_new_funcall1 
-			(fd_sign, gnm_expr_copy (g_slist_nth_data ((GSList *) args, 0)));
-		expr_mode_zero = gnm_expr_new_binary 
-			(expr_sign,
-			 GNM_EXPR_OP_MULT,
-			 gnm_expr_new_funcall2 (fd_ceiling,
-						gnm_expr_new_funcall1 
-						(fd_abs, 
-						 gnm_expr_copy (g_slist_nth_data ((GSList *) args, 0))),
-						gnm_expr_new_binary 
-						(gnm_expr_copy (expr_sign),
-						 GNM_EXPR_OP_MULT, 
-						 gnm_expr_copy (g_slist_nth_data ((GSList *) args, 1)))));
+		expr_mode_zero = gnm_expr_new_funcall3
+			(fd_if,
+			 gnm_expr_new_binary 
+			 (gnm_expr_copy (expr_x),
+			  GNM_EXPR_OP_LT,
+			  gnm_expr_new_constant (value_new_int (0))),
+			 gnm_expr_new_funcall2 
+			 (fd_floor,
+			  gnm_expr_copy (expr_x),
+			  gnm_expr_copy (expr_sig)),
+			 gnm_expr_new_funcall2 
+			 (fd_ceiling,
+			  gnm_expr_copy (expr_x),
+			  gnm_expr_copy (expr_sig)));
 		if (argc == 2) {
 			gnm_expr_list_unref (args);
 			return expr_mode_zero;
 		}
 
 		expr_mode_one = 
-			gnm_expr_new_funcall2 (fd_ceiling,
-					       gnm_expr_copy (g_slist_nth_data ((GSList *) args, 0)),
-					       gnm_expr_copy (g_slist_nth_data ((GSList *) args, 1)));
+			gnm_expr_new_funcall2 
+			(fd_ceiling,
+			 gnm_expr_copy (expr_x),
+			 gnm_expr_copy (expr_sig));
 
 		expr_mode = g_slist_nth_data ((GSList *) args, 2);
 		if (GNM_EXPR_GET_OPER (expr_mode) == GNM_EXPR_OP_CONSTANT) {
@@ -3657,13 +3660,14 @@ odf_func_ceiling_handler (GnmConventions const *convs, Workbook *scope, GnmExprL
 				}
 			}
 		}
-		expr_if = gnm_expr_new_funcall3 (fd_if,
-						 gnm_expr_new_binary 
-						 (gnm_expr_new_constant (value_new_int (0)),
-						  GNM_EXPR_OP_EQUAL,
-						  gnm_expr_copy (expr_mode)),
-						 expr_mode_zero,
-						 expr_mode_one);
+		expr_if = gnm_expr_new_funcall3 
+			(fd_if,
+			 gnm_expr_new_binary 
+			 (gnm_expr_new_constant (value_new_int (0)),
+			  GNM_EXPR_OP_EQUAL,
+			  gnm_expr_copy (expr_mode)),
+			 expr_mode_zero,
+			 expr_mode_one);
 		gnm_expr_list_unref (args);
 		return expr_if;
 	}



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