Commit aba702b5 authored by Jody Goldberg's avatar Jody Goldberg Committed by Jody Goldberg

Bug 12042

2000-06-13  Jody Goldberg <jgoldberg@home.com>

	* src/functions/fn-math.c (callback_function_sumproduct) : Handle
	  empty.
	(gnumeric_sumproduct) : Handle blank cells correctly, correct error
	  handling slightly.

	* src/func.c (iterate_cellrange_callback) : Handle empty cells.
	(function_iterate_do_value) : Add a new argument to control the
	  handling of empty cells.
	(function_iterate_argument_values) : Hard code the ignore_blanks
	  argument to TRUE the same as the previous behavior.
parent 1b9ee9c0
......@@ -4,6 +4,9 @@ and longer term bugs.
Release Critical
----------------
- print preview is not drawing the background colours for cells.
This is likely a gnome-print problem.
- Changing the size of all rows/cols creates big xml files.
- Changing an expression name that is in use causes a crash.
- Saving xml should not rely on changing the textdomain to disable translation
......@@ -13,7 +16,6 @@ Release Critical
essentially requires columns to be selected right-to-left because
stripping is done too early and mangles columns.
Long term breakage
------------------
- The max row/col canvas scroll size is still hard coded.
......@@ -64,9 +66,7 @@ Dialogs
Function Breakage
-----------------
- Index : does not support 0,0 or reference syntax.
- Sumif : mis-handles blanks.
- ftest : Needs auditing. All calls to eval_pos_init_cellref are questionable.
- sumproduct : bug 12042
Printing
--------
......
......@@ -29,7 +29,7 @@ You need:
gnome-libs-1.0.57
gnome-print-0.20
gnome-xml-1.8.5
gnome-xml-1.8.7
libglade-0.13
Optionally:
......
......@@ -3289,10 +3289,10 @@ callback_function_sumproduct (const EvalPos *ep, Value *value,
math_sumproduct_t *mm = closure;
float_t x;
if (!VALUE_IS_NUMBER (value))
x = 0;
else
if (value != NULL && VALUE_IS_NUMBER (value))
x = value_get_as_float (value);
else
x = 0;
if (mm->first) {
gpointer p;
......@@ -3310,22 +3310,21 @@ callback_function_sumproduct (const EvalPos *ep, Value *value,
}
static Value *
gnumeric_sumproduct (FunctionEvalInfo *ei, GList *expr_node_list)
gnumeric_sumproduct (FunctionEvalInfo *ei, GList *args)
{
math_sumproduct_t p;
GSList *current;
float_t sum;
Value *result=NULL;
if (expr_node_list == NULL)
if (args == NULL)
return value_new_error (ei->pos, gnumeric_err_NUM);
p.components = NULL;
p.first = TRUE;
for ( ; result == NULL && expr_node_list;
expr_node_list = expr_node_list->next) {
ExprTree *tree = (ExprTree *) expr_node_list->data;
for ( ; result == NULL && args; args = args->next) {
ExprTree *tree = (ExprTree *) args->data;
Value *val;
val = eval_expr (ei->pos, tree, EVAL_PERMIT_NON_SCALAR);
......@@ -3334,7 +3333,7 @@ gnumeric_sumproduct (FunctionEvalInfo *ei, GList *expr_node_list)
p.current = p.components;
result = function_iterate_do_value (
ei->pos, callback_function_sumproduct, &p,
val, TRUE);
val, FALSE, FALSE);
value_release (val);
} else
......@@ -3342,16 +3341,19 @@ gnumeric_sumproduct (FunctionEvalInfo *ei, GList *expr_node_list)
p.first = FALSE;
}
sum = 0;
for (current=p.components; current != NULL ; current = current->next) {
gpointer p = current->data;
sum += *((float_t *) p);
g_free(current->data);
if (result == NULL) {
sum = 0;
for (current = p.components; current != NULL ; current = current->next) {
gpointer p = current->data;
sum += *((float_t *) p);
g_free(current->data);
}
}
g_slist_free(p.components);
if (expr_node_list)
/* If something was a different size */
if (result != NULL)
return value_new_error (ei->pos, gnumeric_err_VALUE);
return value_new_float (sum);
......
......@@ -1411,7 +1411,7 @@ gnumeric_chitest (FunctionEvalInfo *ei, Value **argv)
ret = function_iterate_do_value (ei->pos, (FunctionIterateCallback)
callback_function_chitest_actual,
&p1, argv[0],
TRUE);
TRUE, TRUE);
if (ret != NULL)
return value_new_error (ei->pos, gnumeric_err_NUM);
......@@ -1422,7 +1422,7 @@ gnumeric_chitest (FunctionEvalInfo *ei, Value **argv)
ret = function_iterate_do_value (ei->pos, (FunctionIterateCallback)
callback_function_chitest_theoretical,
&p2, argv[1],
TRUE);
TRUE, TRUE);
if (ret != NULL)
return value_new_error (ei->pos, gnumeric_err_NUM);
......@@ -3181,7 +3181,7 @@ gnumeric_percentrank (FunctionEvalInfo *ei, Value **argv)
ret = function_iterate_do_value (ei->pos, (FunctionIterateCallback)
callback_function_percentrank,
&p, argv[0],
TRUE);
TRUE, TRUE);
if (ret != NULL || (p.smaller + p.greater + p.equal == 0))
return value_new_error (ei->pos, gnumeric_err_NUM);
......
......@@ -42,6 +42,13 @@ iterate_cellrange_callback (Sheet *sheet, int col, int row,
EvalPos ep;
Value *res;
if (cell == NULL) {
ep.sheet = sheet;
ep.eval.col = col;
ep.eval.row = row;
return (*data->callback)(&ep, NULL, data->closure);
}
if (cell->generation != sheet->workbook->generation)
cell_eval (cell);
......@@ -64,7 +71,8 @@ function_iterate_do_value (EvalPos const *ep,
FunctionIterateCallback callback,
void *closure,
Value *value,
gboolean strict)
gboolean strict,
gboolean ignore_blank)
{
Value *res = NULL;
......@@ -93,7 +101,7 @@ function_iterate_do_value (EvalPos const *ep,
res = function_iterate_do_value (
ep, callback, closure,
value->v_array.vals [x][y],
strict);
strict, TRUE);
if (res != NULL)
return res;
}
......@@ -107,7 +115,7 @@ function_iterate_do_value (EvalPos const *ep,
data.closure = closure;
data.strict = strict;
res = workbook_foreach_cell_in_range (ep, value, TRUE,
res = workbook_foreach_cell_in_range (ep, value, ignore_blank,
iterate_cellrange_callback,
&data);
}
......@@ -143,7 +151,7 @@ function_iterate_argument_values (const EvalPos *ep,
}
result = function_iterate_do_value (ep, callback, callback_closure,
val, strict);
val, strict, TRUE);
value_release (val);
}
return result;
......
......@@ -68,7 +68,8 @@ Value *function_iterate_do_value (const EvalPos *fp,
FunctionIterateCallback callback,
void *closure,
Value *value,
gboolean strict);
gboolean strict,
gboolean ignore_blank);
Value *function_call_with_list (FunctionEvalInfo *ei,
GList *args);
......
......@@ -3289,10 +3289,10 @@ callback_function_sumproduct (const EvalPos *ep, Value *value,
math_sumproduct_t *mm = closure;
float_t x;
if (!VALUE_IS_NUMBER (value))
x = 0;
else
if (value != NULL && VALUE_IS_NUMBER (value))
x = value_get_as_float (value);
else
x = 0;
if (mm->first) {
gpointer p;
......@@ -3310,22 +3310,21 @@ callback_function_sumproduct (const EvalPos *ep, Value *value,
}
static Value *
gnumeric_sumproduct (FunctionEvalInfo *ei, GList *expr_node_list)
gnumeric_sumproduct (FunctionEvalInfo *ei, GList *args)
{
math_sumproduct_t p;
GSList *current;
float_t sum;
Value *result=NULL;
if (expr_node_list == NULL)
if (args == NULL)
return value_new_error (ei->pos, gnumeric_err_NUM);
p.components = NULL;
p.first = TRUE;
for ( ; result == NULL && expr_node_list;
expr_node_list = expr_node_list->next) {
ExprTree *tree = (ExprTree *) expr_node_list->data;
for ( ; result == NULL && args; args = args->next) {
ExprTree *tree = (ExprTree *) args->data;
Value *val;
val = eval_expr (ei->pos, tree, EVAL_PERMIT_NON_SCALAR);
......@@ -3334,7 +3333,7 @@ gnumeric_sumproduct (FunctionEvalInfo *ei, GList *expr_node_list)
p.current = p.components;
result = function_iterate_do_value (
ei->pos, callback_function_sumproduct, &p,
val, TRUE);
val, FALSE, FALSE);
value_release (val);
} else
......@@ -3342,16 +3341,19 @@ gnumeric_sumproduct (FunctionEvalInfo *ei, GList *expr_node_list)
p.first = FALSE;
}
sum = 0;
for (current=p.components; current != NULL ; current = current->next) {
gpointer p = current->data;
sum += *((float_t *) p);
g_free(current->data);
if (result == NULL) {
sum = 0;
for (current = p.components; current != NULL ; current = current->next) {
gpointer p = current->data;
sum += *((float_t *) p);
g_free(current->data);
}
}
g_slist_free(p.components);
if (expr_node_list)
/* If something was a different size */
if (result != NULL)
return value_new_error (ei->pos, gnumeric_err_VALUE);
return value_new_float (sum);
......
......@@ -1411,7 +1411,7 @@ gnumeric_chitest (FunctionEvalInfo *ei, Value **argv)
ret = function_iterate_do_value (ei->pos, (FunctionIterateCallback)
callback_function_chitest_actual,
&p1, argv[0],
TRUE);
TRUE, TRUE);
if (ret != NULL)
return value_new_error (ei->pos, gnumeric_err_NUM);
......@@ -1422,7 +1422,7 @@ gnumeric_chitest (FunctionEvalInfo *ei, Value **argv)
ret = function_iterate_do_value (ei->pos, (FunctionIterateCallback)
callback_function_chitest_theoretical,
&p2, argv[1],
TRUE);
TRUE, TRUE);
if (ret != NULL)
return value_new_error (ei->pos, gnumeric_err_NUM);
......@@ -3181,7 +3181,7 @@ gnumeric_percentrank (FunctionEvalInfo *ei, Value **argv)
ret = function_iterate_do_value (ei->pos, (FunctionIterateCallback)
callback_function_percentrank,
&p, argv[0],
TRUE);
TRUE, TRUE);
if (ret != NULL || (p.smaller + p.greater + p.equal == 0))
return value_new_error (ei->pos, gnumeric_err_NUM);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment