Commit 8a51b8ce authored by Morten Welinder's avatar Morten Welinder

Post-Michael cleanup.

parent 0600c06c
1999-06-24 <michael@edenproject.org>
1999-06-23 Morten Welinder <terra@diku.dk>
* src/fn-stat.c (gnumeric_poisson): Fix formula and error
handling.
(gnumeric_binomdist): Ditto.
(gnumeric_correl): Ditto.
* src/expr.c (eval_expr): Remove useless casts.
(eval_funcall): Treat 'b' as 'f' for now. Don't use fd until it
gets a value.
* src/func.c (function_iterate_argument_values): Don't leak error
message.
* src/eval.c (cell_eval): Don't leak error message.
* src/*.c: Remove strange casts to (Value *).
1999-06-24 Michael Meeks <michael@edenproject.org>
* src/expr.c (error_message_new): Fix stupid bug,
such that every error was set.
......@@ -22,7 +40,6 @@
(workbook_set_auto_expr): Hacked to cache expression until we
have a sheet context.
* src/expr.h: Add extra Parser error type for invalid args.
* src/fn-financial.c (finance_functions_init): Fix financial
......
1999-06-24 <michael@edenproject.org>
1999-06-23 Morten Welinder <terra@diku.dk>
* src/fn-stat.c (gnumeric_poisson): Fix formula and error
handling.
(gnumeric_binomdist): Ditto.
(gnumeric_correl): Ditto.
* src/expr.c (eval_expr): Remove useless casts.
(eval_funcall): Treat 'b' as 'f' for now. Don't use fd until it
gets a value.
* src/func.c (function_iterate_argument_values): Don't leak error
message.
* src/eval.c (cell_eval): Don't leak error message.
* src/*.c: Remove strange casts to (Value *).
1999-06-24 Michael Meeks <michael@edenproject.org>
* src/expr.c (error_message_new): Fix stupid bug,
such that every error was set.
......@@ -22,7 +40,6 @@
(workbook_set_auto_expr): Hacked to cache expression until we
have a sheet context.
* src/expr.h: Add extra Parser error type for invalid args.
* src/fn-financial.c (finance_functions_init): Fix financial
......
1999-06-24 <michael@edenproject.org>
1999-06-23 Morten Welinder <terra@diku.dk>
* src/fn-stat.c (gnumeric_poisson): Fix formula and error
handling.
(gnumeric_binomdist): Ditto.
(gnumeric_correl): Ditto.
* src/expr.c (eval_expr): Remove useless casts.
(eval_funcall): Treat 'b' as 'f' for now. Don't use fd until it
gets a value.
* src/func.c (function_iterate_argument_values): Don't leak error
message.
* src/eval.c (cell_eval): Don't leak error message.
* src/*.c: Remove strange casts to (Value *).
1999-06-24 Michael Meeks <michael@edenproject.org>
* src/expr.c (error_message_new): Fix stupid bug,
such that every error was set.
......@@ -22,7 +40,6 @@
(workbook_set_auto_expr): Hacked to cache expression until we
have a sheet context.
* src/expr.h: Add extra Parser error type for invalid args.
* src/fn-financial.c (finance_functions_init): Fix financial
......
1999-06-24 <michael@edenproject.org>
1999-06-23 Morten Welinder <terra@diku.dk>
* src/fn-stat.c (gnumeric_poisson): Fix formula and error
handling.
(gnumeric_binomdist): Ditto.
(gnumeric_correl): Ditto.
* src/expr.c (eval_expr): Remove useless casts.
(eval_funcall): Treat 'b' as 'f' for now. Don't use fd until it
gets a value.
* src/func.c (function_iterate_argument_values): Don't leak error
message.
* src/eval.c (cell_eval): Don't leak error message.
* src/*.c: Remove strange casts to (Value *).
1999-06-24 Michael Meeks <michael@edenproject.org>
* src/expr.c (error_message_new): Fix stupid bug,
such that every error was set.
......@@ -22,7 +40,6 @@
(workbook_set_auto_expr): Hacked to cache expression until we
have a sheet context.
* src/expr.h: Add extra Parser error type for invalid args.
* src/fn-financial.c (finance_functions_init): Fix financial
......
......@@ -164,7 +164,7 @@ gnumeric_if (FunctionEvalInfo *ei, GList *expr_node_list)
return function_error (ei, _("Invalid number of arguments"));
/* Compute the if part */
value = (Value *)eval_expr (ei, (ExprTree *) expr_node_list->data);
value = eval_expr (ei, (ExprTree *) expr_node_list->data);
if (value == NULL)
return NULL;
......
......@@ -147,7 +147,7 @@ gnumeric_choose (FunctionEvalInfo *ei, GList *l)
if (argc < 1 || !l->data)
return function_error (ei, _("#ARG!"));
v = (Value *)eval_expr (ei, l->data);
v = eval_expr (ei, l->data);
if (!v)
return NULL;
......@@ -519,7 +519,7 @@ gnumeric_column (FunctionEvalInfo *ei, GList *nodes)
if (!nodes || !nodes->data)
return value_new_int (ei->pos.eval_col+1);
v = (Value *)eval_expr (ei, nodes->data);
v = eval_expr (ei, nodes->data);
if (!v)
return NULL;
......@@ -623,7 +623,7 @@ gnumeric_row (FunctionEvalInfo *ei, GList *nodes)
if (!nodes || !nodes->data)
return value_new_int (ei->pos.eval_row+1);
v = (Value *)eval_expr (ei, nodes->data);
v = eval_expr (ei, nodes->data);
if (!v)
return NULL;
......
......@@ -2372,7 +2372,7 @@ gnumeric_seriessum (FunctionEvalInfo *ei, GList *nodes)
if (tree == NULL)
return function_error (ei, gnumeric_err_NUM);
val = (Value *)eval_expr (ei, tree);
val = eval_expr (ei, tree);
if (!val) return NULL;
if (! VALUE_IS_NUMBER(val))
return function_error (ei, gnumeric_err_VALUE);
......@@ -2386,7 +2386,7 @@ gnumeric_seriessum (FunctionEvalInfo *ei, GList *nodes)
if (tree == NULL)
return function_error (ei, gnumeric_err_NUM);
val = (Value *)eval_expr (ei, tree);
val = eval_expr (ei, tree);
if (!val) return NULL;
if (! VALUE_IS_NUMBER(val)) {
value_release (val);
......@@ -2402,7 +2402,7 @@ gnumeric_seriessum (FunctionEvalInfo *ei, GList *nodes)
if (tree == NULL)
return function_error (ei, gnumeric_err_NUM);
val = (Value *)eval_expr (ei, tree);
val = eval_expr (ei, tree);
if (!val) return NULL;
if (! VALUE_IS_NUMBER(val)) {
value_release (val);
......
......@@ -510,8 +510,8 @@ gnumeric_correl (FunctionEvalInfo *ei, GList *expr_node_list)
if (tmp == 0)
return value_new_float (0);
else
return value_new_float ((sum - (pr.sum1*pr.sum2/pr.count) /
sqrt(tmp)));
return value_new_float ((sum - (pr.sum1*pr.sum2/pr.count)) /
sqrt(tmp));
}
static char *help_negbinomdist = {
......@@ -909,14 +909,14 @@ gnumeric_average (FunctionEvalInfo *ei, GList *expr_node_list)
Value *vtmp;
float_t sum, count;
vtmp = (Value *)gnumeric_sum (ei, expr_node_list);
vtmp = gnumeric_sum (ei, expr_node_list);
if (!vtmp)
return NULL;
sum = value_get_as_float (vtmp);
value_release (vtmp);
vtmp = (Value *)gnumeric_count (ei, expr_node_list);
vtmp = gnumeric_count (ei, expr_node_list);
if (!vtmp)
return NULL;
......@@ -1547,13 +1547,13 @@ static char *help_binomdist = {
"@n is the number of successes, @trials is the total number of "
"independent trials, @p is the probability of success in trials, "
"and @cumulative describes whether to return the sum of the"
"binomial function from 0 to n."
"binomial function from 0 to @n."
"\n"
"Performing this function on a string or empty cell returns an error."
"if n or trials is a non-integer it is truncated. "
"if n < 0 or trials < 0 BINOMDIST returns #NUM! error. "
"if n > trials BINOMDIST returns #NUM! error. "
"if p < 0 or p > 1 BINOMDIST returns #NUM! error."
"if @n or @trials are non-integer they are truncated. "
"if @n < 0 or @trials < 0 BINOMDIST returns #NUM! error. "
"if @n > trials BINOMDIST returns #NUM! error. "
"if @p < 0 or @p > 1 BINOMDIST returns #NUM! error."
"\n"
"@SEEALSO=POISSON")
};
......@@ -1561,33 +1561,28 @@ static char *help_binomdist = {
static Value *
gnumeric_binomdist (FunctionEvalInfo *ei, Value **argv)
{
int n, trials;
int n, trials, cuml, err;
float_t p;
int cuml, err, x;
if (!VALUE_IS_NUMBER(argv[0]) ||
!VALUE_IS_NUMBER(argv[1]) ||
!VALUE_IS_NUMBER(argv[2]))
return function_error (ei, gnumeric_err_VALUE);
n = value_get_as_int (argv [0]);
trials = value_get_as_int (argv [1]);
p = value_get_as_float (argv[2]);
cuml = value_get_as_bool (argv[3], &err);
if (n<0 || trials<0 || p<0 || p>1 || n>trials)
if (n<0 || trials<0 || p<0 || p>1 || n>trials || err)
return function_error (ei, gnumeric_err_NUM);
cuml = value_get_as_bool (argv[3], &err);
if (cuml){
float_t v=0;
int x;
for (x=0; x<=n; x++)
v += (combin(trials, x) * pow(p, x) *
pow(1-p, trials-x));
return value_new_float (v);
} else
return value_new_float (combin(trials, n) * pow(p, n *
pow(1-p, trials-n)));
return value_new_float (combin(trials, n) * pow(p, n) *
pow(1-p, trials-n));
}
static char *help_critbinom = {
......@@ -1938,14 +1933,14 @@ gnumeric_kurt (FunctionEvalInfo *ei, GList *expr_node_list)
pr.num = 0;
pr.sum = 0.0;
vtmp = (Value *)gnumeric_average (ei, expr_node_list);
vtmp = gnumeric_average (ei, expr_node_list);
if (!vtmp)
return NULL;
pr.mean = value_get_as_float (vtmp);
value_release (vtmp);
vtmp = (Value *)gnumeric_stdev (ei, expr_node_list);
vtmp = gnumeric_stdev (ei, expr_node_list);
if (!vtmp)
return NULL;
......@@ -2070,17 +2065,16 @@ static char *help_poisson = {
static Value *
gnumeric_poisson (FunctionEvalInfo *ei, Value **argv)
{
float_t x, mean;
int cuml, err;
float_t mean;
int x, cuml, err;
x = value_get_as_int (argv [0]);
mean = value_get_as_float (argv [1]);
cuml = value_get_as_bool (argv[2], &err);
if (x<=0 || mean <=0)
if (x<=0 || mean <=0 || err)
return function_error (ei, gnumeric_err_NUM);
cuml = value_get_as_bool (argv[2], &err);
if (cuml) {
int k;
float_t sum = 0;
......@@ -2090,8 +2084,8 @@ gnumeric_poisson (FunctionEvalInfo *ei, Value **argv)
return value_new_float (sum);
} else
return value_new_float (exp(-mean)*pow(mean,x /
exp (lgamma (x + 1))));
return value_new_float (exp(-mean)*pow(mean,x) /
exp (lgamma (x + 1)));
}
static char *help_pearson = {
......@@ -2116,7 +2110,7 @@ gnumeric_pearson (FunctionEvalInfo *ei, GList *expr_node_list)
GSList *list1, *list2;
Value *vtmp;
vtmp = (Value *)gnumeric_count (ei, expr_node_list);
vtmp = gnumeric_count (ei, expr_node_list);
if (!vtmp)
return NULL;
......
......@@ -293,7 +293,7 @@ gnumeric_concatenate (FunctionEvalInfo *ei, GList *l)
s = g_new(gchar, 1);
*s = '\0';
while ( l != NULL &&
(v=(Value *)eval_expr(ei, l->data)) != NULL) {
(v=eval_expr(ei, l->data)) != NULL) {
/*
if (v->type != VALUE_STRING) {
return function_error (ei, _("Invalid argument"));
......@@ -826,7 +826,7 @@ gnumeric_dollar (FunctionEvalInfo *ei, Value **argv)
ag[1] = argv [1];
ag[2] = NULL;
v = (Value *)gnumeric_fixed (ei, ag);
v = gnumeric_fixed (ei, ag);
if (v == NULL)
return NULL;
......
......@@ -36,7 +36,7 @@ cell_eval (Cell *cell)
}
#endif
v = (Value *)eval_expr (func_eval_info_cell (&s, cell), cell->parsed_node);
v = eval_expr (func_eval_info_cell (&s, cell), cell->parsed_node);
#ifdef DEBUG_EVALUATION
{
......@@ -65,6 +65,8 @@ cell_eval (Cell *cell)
cell->flags &= ~CELL_ERROR;
}
error_message_free (s.error);
cell_calc_dimensions (cell);
sheet_redraw_cell_region (cell->sheet,
......
......@@ -36,7 +36,7 @@ cell_eval (Cell *cell)
}
#endif
v = (Value *)eval_expr (func_eval_info_cell (&s, cell), cell->parsed_node);
v = eval_expr (func_eval_info_cell (&s, cell), cell->parsed_node);
#ifdef DEBUG_EVALUATION
{
......@@ -65,6 +65,8 @@ cell_eval (Cell *cell)
cell->flags &= ~CELL_ERROR;
}
error_message_free (s.error);
cell_calc_dimensions (cell);
sheet_redraw_cell_region (cell->sheet,
......
......@@ -923,8 +923,6 @@ eval_funcall (FunctionEvalInfo *s, ExprTree *tree)
eval_col = s->pos.eval_col;
eval_row = s->pos.eval_row;
s->func_def = fd;
l = tree->u.function.arg_list;
argc = g_list_length (l);
......@@ -932,6 +930,7 @@ eval_funcall (FunctionEvalInfo *s, ExprTree *tree)
return function_error (s, _("Internal error"));
fd = (FunctionDefinition *)sym->data;
s->func_def = fd;
if (fd->fn_type == FUNCTION_NODES) {
/* Functions that deal with ExprNodes */
......@@ -972,7 +971,7 @@ eval_funcall (FunctionEvalInfo *s, ExprTree *tree)
if ((*arg_type != 'A' && /* This is so a cell reference */
*arg_type != 'r') || /* can be converted to a cell range */
!t || (t->oper != OPER_VAR)) { /* without being evaluated */
if ((v = (Value *)eval_expr (s, t)) == NULL)
if ((v = eval_expr (s, t)) == NULL)
goto free_list;
} else {
g_assert (t->oper == OPER_VAR);
......@@ -986,7 +985,7 @@ eval_funcall (FunctionEvalInfo *s, ExprTree *tree)
switch (*arg_type){
case 'f':
case 'b':
if (v->type != VALUE_INTEGER &&
v->type != VALUE_FLOAT)
type_mismatch = 1;
......@@ -1224,11 +1223,11 @@ eval_expr (FunctionEvalInfo *s, ExprTree *tree)
case OPER_LTE: {
int comp;
a = (Value *)eval_expr (s, tree->u.binary.value_a);
a = eval_expr (s, tree->u.binary.value_a);
if (!a)
return NULL;
b = (Value *)eval_expr (s, tree->u.binary.value_b);
b = eval_expr (s, tree->u.binary.value_b);
if (!b) {
value_release (a);
return NULL;
......@@ -1273,7 +1272,7 @@ eval_expr (FunctionEvalInfo *s, ExprTree *tree)
error_message_set (s->error, _("Internal type error"));
res = NULL;
}
return (Value *)res;
return res;
}
case OPER_ADD:
......@@ -1281,12 +1280,12 @@ eval_expr (FunctionEvalInfo *s, ExprTree *tree)
case OPER_MULT:
case OPER_DIV:
case OPER_EXP:
a = (Value *)eval_expr (s, tree->u.binary.value_a);
a = eval_expr (s, tree->u.binary.value_a);
if (!a)
return NULL;
b = (Value *)eval_expr (s, tree->u.binary.value_b);
b = eval_expr (s, tree->u.binary.value_b);
if (!b){
value_release (a);
......@@ -1399,15 +1398,15 @@ eval_expr (FunctionEvalInfo *s, ExprTree *tree)
}
value_release (a);
value_release (b);
return (Value *)res;
return res;
case OPER_CONCAT: {
char *sa, *sb, *tmp;
a = (Value *)eval_expr (s, tree->u.binary.value_a);
a = eval_expr (s, tree->u.binary.value_a);
if (!a)
return NULL;
b = (Value *)eval_expr (s, tree->u.binary.value_b);
b = eval_expr (s, tree->u.binary.value_b);
if (!b){
value_release (a);
return NULL;
......@@ -1424,7 +1423,7 @@ eval_expr (FunctionEvalInfo *s, ExprTree *tree)
value_release (a);
value_release (b);
return (Value *)res;
return res;
}
case OPER_FUNCALL:
......@@ -1456,7 +1455,7 @@ eval_expr (FunctionEvalInfo *s, ExprTree *tree)
}
if (cell->value)
return (Value *)value_duplicate (cell->value);
return value_duplicate (cell->value);
else {
if (cell->text)
error_message_set (s->error, cell->text->str);
......@@ -1466,14 +1465,14 @@ eval_expr (FunctionEvalInfo *s, ExprTree *tree)
}
}
return (Value *)value_new_int (0);
return value_new_int (0);
}
case OPER_CONSTANT:
return (Value *)value_duplicate (tree->u.constant);
return value_duplicate (tree->u.constant);
case OPER_NEG:
a = (Value *)eval_expr (s, tree->u.value);
a = eval_expr (s, tree->u.value);
if (!a)
return NULL;
if (!VALUE_IS_NUMBER (a)){
......@@ -1486,7 +1485,7 @@ eval_expr (FunctionEvalInfo *s, ExprTree *tree)
else
res = value_new_float (-a->v.v_float);
value_release (a);
return (Value *)res;
return res;
}
error_message_set (s->error, _("Unknown evaluation error"));
......
......@@ -164,7 +164,7 @@ gnumeric_if (FunctionEvalInfo *ei, GList *expr_node_list)
return function_error (ei, _("Invalid number of arguments"));
/* Compute the if part */
value = (Value *)eval_expr (ei, (ExprTree *) expr_node_list->data);
value = eval_expr (ei, (ExprTree *) expr_node_list->data);
if (value == NULL)
return NULL;
......
......@@ -147,7 +147,7 @@ gnumeric_choose (FunctionEvalInfo *ei, GList *l)
if (argc < 1 || !l->data)
return function_error (ei, _("#ARG!"));
v = (Value *)eval_expr (ei, l->data);
v = eval_expr (ei, l->data);
if (!v)
return NULL;
......@@ -519,7 +519,7 @@ gnumeric_column (FunctionEvalInfo *ei, GList *nodes)
if (!nodes || !nodes->data)
return value_new_int (ei->pos.eval_col+1);
v = (Value *)eval_expr (ei, nodes->data);
v = eval_expr (ei, nodes->data);
if (!v)
return NULL;
......@@ -623,7 +623,7 @@ gnumeric_row (FunctionEvalInfo *ei, GList *nodes)
if (!nodes || !nodes->data)
return value_new_int (ei->pos.eval_row+1);
v = (Value *)eval_expr (ei, nodes->data);
v = eval_expr (ei, nodes->data);
if (!v)
return NULL;
......
......@@ -2372,7 +2372,7 @@ gnumeric_seriessum (FunctionEvalInfo *ei, GList *nodes)
if (tree == NULL)
return function_error (ei, gnumeric_err_NUM);
val = (Value *)eval_expr (ei, tree);
val = eval_expr (ei, tree);
if (!val) return NULL;
if (! VALUE_IS_NUMBER(val))
return function_error (ei, gnumeric_err_VALUE);
......@@ -2386,7 +2386,7 @@ gnumeric_seriessum (FunctionEvalInfo *ei, GList *nodes)
if (tree == NULL)
return function_error (ei, gnumeric_err_NUM);
val = (Value *)eval_expr (ei, tree);
val = eval_expr (ei, tree);
if (!val) return NULL;
if (! VALUE_IS_NUMBER(val)) {
value_release (val);
......@@ -2402,7 +2402,7 @@ gnumeric_seriessum (FunctionEvalInfo *ei, GList *nodes)
if (tree == NULL)
return function_error (ei, gnumeric_err_NUM);
val = (Value *)eval_expr (ei, tree);
val = eval_expr (ei, tree);
if (!val) return NULL;
if (! VALUE_IS_NUMBER(val)) {
value_release (val);
......
......@@ -510,8 +510,8 @@ gnumeric_correl (FunctionEvalInfo *ei, GList *expr_node_list)
if (tmp == 0)
return value_new_float (0);
else
return value_new_float ((sum - (pr.sum1*pr.sum2/pr.count) /
sqrt(tmp)));
return value_new_float ((sum - (pr.sum1*pr.sum2/pr.count)) /
sqrt(tmp));
}
static char *help_negbinomdist = {
......@@ -909,14 +909,14 @@ gnumeric_average (FunctionEvalInfo *ei, GList *expr_node_list)
Value *vtmp;
float_t sum, count;
vtmp = (Value *)gnumeric_sum (ei, expr_node_list);
vtmp = gnumeric_sum (ei, expr_node_list);
if (!vtmp)
return NULL;
sum = value_get_as_float (vtmp);
value_release (vtmp);
vtmp = (Value *)gnumeric_count (ei, expr_node_list);
vtmp = gnumeric_count (ei, expr_node_list);
if (!vtmp)
return NULL;
......@@ -1547,13 +1547,13 @@ static char *help_binomdist = {
"@n is the number of successes, @trials is the total number of "
"independent trials, @p is the probability of success in trials, "
"and @cumulative describes whether to return the sum of the"
"binomial function from 0 to n."
"binomial function from 0 to @n."
"\n"
"Performing this function on a string or empty cell returns an error."
"if n or trials is a non-integer it is truncated. "
"if n < 0 or trials < 0 BINOMDIST returns #NUM! error. "
"if n > trials BINOMDIST returns #NUM! error. "
"if p < 0 or p > 1 BINOMDIST returns #NUM! error."
"if @n or @trials are non-integer they are truncated. "
"if @n < 0 or @trials < 0 BINOMDIST returns #NUM! error. "
"if @n > trials BINOMDIST returns #NUM! error. "
"if @p < 0 or @p > 1 BINOMDIST returns #NUM! error."
"\n"
"@SEEALSO=POISSON")
};
......@@ -1561,33 +1561,28 @@ static char *help_binomdist = {
static Value *
gnumeric_binomdist (FunctionEvalInfo *ei, Value **argv)
{
int n, trials;
int n, trials, cuml, err;
float_t p;
int cuml, err, x;
if (!VALUE_IS_NUMBER(argv[0]) ||
!VALUE_IS_NUMBER(argv[1]) ||
!VALUE_IS_NUMBER(argv[2]))
return function_error (ei, gnumeric_err_VALUE);
n = value_get_as_int (argv [0]);
trials = value_get_as_int (argv [1]);
p = value_get_as_float (argv[2]);
cuml = value_get_as_bool (argv[3], &err);
if (n<0 || trials<0 || p<0 || p>1 || n>trials)
if (n<0 || trials<0 || p<0 || p>1 || n>trials || err)
return function_error (ei, gnumeric_err_NUM);
cuml = value_get_as_bool (argv[3], &err);
if (cuml){
float_t v=0;
int x;
for (x=0; x<=n; x++)
v += (combin(trials, x) * pow(p, x) *
pow(1-p, trials-x));
return value_new_float (v);
} else
return value_new_float (combin(trials, n) * pow(p, n *
pow(1-p, trials-n)));
return value_new_float (combin(trials, n) * pow(p, n) *
pow(1-p, trials-n));
}
static char *help_critbinom = {
......@@ -1938,14 +1933,14 @@ gnumeric_kurt (FunctionEvalInfo *ei, GList *expr_node_list)
pr.num = 0;
pr.sum = 0.0;
vtmp = (Value *)gnumeric_average (ei, expr_node_list);
vtmp = gnumeric_average (ei, expr_node_list);
if (!vtmp)
return NULL;
pr.mean = value_get_as_float (vtmp);
value_release (vtmp);
vtmp = (Value *)gnumeric_stdev (ei, expr_node_list);
vtmp = gnumeric_stdev (ei, expr_node_list);
if (!vtmp)
return NULL;
......@@ -2070,17 +2065,16 @@ static char *help_poisson = {
static Value *
gnumeric_poisson (FunctionEvalInfo *ei, Value **argv)