Commit 0492a6e9 authored by Morten Welinder's avatar Morten Welinder

SUMPRODUCT: improve accuracy

parent 8ff1e826
......@@ -145,7 +145,7 @@ PKG_PROG_PKG_CONFIG(0.18)
dnl *****************************
libspreadsheet_reqs="
libgoffice-${GOFFICE_API_VER} >= 0.9.0
libgoffice-${GOFFICE_API_VER} >= 0.9.1
libgsf-1 >= 1.14.18
libxml-2.0 >= 2.4.12
"
......
2011-11-25 Morten Welinder <terra@gnome.org>
* functions.c (gnumeric_sumproduct_common): Improve accuracy.
2011-11-24 Morten Welinder <terra@gnome.org>
* Release 1.11.0
......
......@@ -3056,17 +3056,26 @@ gnumeric_sumproduct_common (gboolean ignore_bools, GnmFuncEvalInfo *ei,
*/
result = value_new_error_VALUE (ei->pos);
} else {
gnm_float sum = 0;
void *state = gnm_accumulator_start ();
GnmAccumulator *acc = gnm_accumulator_new ();
int j;
for (j = 0; j < sizex * sizey; j++) {
gnm_float product = data[0][j];
for (i = 1; i < argc; i++)
product *= data[i][j];
sum += product;
int i;
GnmQuad product;
gnm_quad_init (&product, data[0][j]);
for (i = 1; i < argc; i++) {
GnmQuad q;
gnm_quad_init (&q, data[i][j]);
gnm_quad_mul (&product, &product, &q);
}
gnm_accumulator_add_quad (acc, &product);
}
result = value_new_float (sum);
result = value_new_float (gnm_accumulator_value (acc));
gnm_accumulator_free (acc);
gnm_accumulator_end (state);
}
done:
......
......@@ -120,6 +120,18 @@ gnm_float gnm_yn (int n, gnm_float x);
#define GNM_EPSILON LDBL_EPSILON
#define GNM_const(_c) _c ## L
#define GnmQuad GOQuadl
#define gnm_quad_init go_quad_initl
#define gnm_quad_mul go_quad_mull
#define GnmAccumulator GOAccumulatorl
#define gnm_accumulator_start go_accumulator_startl
#define gnm_accumulator_end go_accumulator_endl
#define gnm_accumulator_new go_accumulator_newl
#define gnm_accumulator_free go_accumulator_freel
#define gnm_accumulator_add go_accumulator_addl
#define gnm_accumulator_add_quad go_accumulator_add_quadl
#define gnm_accumulator_value go_accumulator_valuel
#else /* !GNM_WITH_LONG_DOUBLE */
typedef double gnm_float;
......@@ -190,6 +202,18 @@ typedef double gnm_float;
#define GNM_EPSILON DBL_EPSILON
#define GNM_const(_c) _c
#define GnmQuad GOQuad
#define gnm_quad_init go_quad_init
#define gnm_quad_mul go_quad_mul
#define GnmAccumulator GOAccumulator
#define gnm_accumulator_start go_accumulator_start
#define gnm_accumulator_end go_accumulator_end
#define gnm_accumulator_new go_accumulator_new
#define gnm_accumulator_free go_accumulator_free
#define gnm_accumulator_add go_accumulator_add
#define gnm_accumulator_add_quad go_accumulator_add_quad
#define gnm_accumulator_value go_accumulator_value
#endif
G_END_DECLS
......
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