Commit ba810ada authored by Morten Welinder's avatar Morten Welinder Committed by Morten Welinder

Just sum. Don't try to be overly smart. (range_sumsq): Ditto.

2005-01-05  Morten Welinder  <terra@gnome.org>

	* src/rangefunc.c (range_sum): Just sum.  Don't try to be overly
	smart.
	(range_sumsq): Ditto.
parent ae005169
2005-01-05 Morten Welinder <terra@gnome.org>
* src/rangefunc.c (range_sum): Just sum. Don't try to be overly
smart.
(range_sumsq): Ditto.
2005-01-05 Jody Goldberg <jody@gnome.org>
* src/gnumeric-pane.c (cb_sheet_object_widget_canvas_event) : handle
......
......@@ -39,6 +39,7 @@ Morten:
[#161909]
* Fix Help->Contents accelerator. [#162865]
* Make general format use "E", not "e", as appropriate.
* Simplyfy SUM. [#131588]
--------------------------------------------------------------------------
Gnumeric 1.4.1
......
2005-01-05 Morten Welinder <terra@gnome.org>
* src/rangefunc.c (range_sum): Just sum. Don't try to be overly
smart.
(range_sumsq): Ditto.
2005-01-05 Jody Goldberg <jody@gnome.org>
* src/gnumeric-pane.c (cb_sheet_object_widget_canvas_event) : handle
......
......@@ -24,59 +24,40 @@ range_count (const gnm_float *xs, int n, gnm_float *res)
/* Arithmetic sum. */
/* We are using the double pass algorithm 2.3.1 described in */
/* Thisted: Elements of Statistical Computing */
/* Note: mathematically sum_2 should be zero, except that it */
/* contains some of the numerical errors from the first pass */
int
range_sum (const gnm_float *xs, int n, gnm_float *res)
{
/* http://bugzilla.gnome.org/show_bug.cgi?id=131588 */
/* http://bugzilla.gnome.org/show_bug.cgi?id=131588 */
#ifdef HAVE_LONG_DOUBLE
long double sum_1 = 0., sum_2 = 0., xbar = 0.;
long double sum = 0;
#else
gnm_float sum_1 = 0., sum_2 = 0., xbar = 0.;
gnm_float sum = 0;
#endif
int i;
if (n == 0) {
*res = 0.0;
return 0;
}
for (i = 0; i < n; i++)
sum_1 += xs[i];
xbar = sum_1 / n;
for (i = 0; i < n; i++)
sum_2 += (xs[i] - xbar);
*res = sum_1 + sum_2;
sum += xs[i];
*res = sum;
return 0;
}
/* Arithmetic sum of squares. */
/* See the explanation for the Arithmetic sum above.*/
int
range_sumsq (const gnm_float *xs, int n, gnm_float *res)
{
/* http://bugzilla.gnome.org/show_bug.cgi?id=131588 */
/* http://bugzilla.gnome.org/show_bug.cgi?id=131588 */
#ifdef HAVE_LONG_DOUBLE
long double sum_1 = 0., sum_2 = 0., xbar = 0.;
long double sum = 0;
#else
gnm_float sum_1 = 0., sum_2 = 0., xbar = 0.;
gnm_float sum = 0;
#endif
int i;
if (n == 0) {
*res = 0.0;
return 0;
}
for (i = 0; i < n; i++)
sum_1 += xs[i] * xs[i];
xbar = sum_1 / n;
for (i = 0; i < n; i++)
sum_1 += ((xs[i] * xs[i]) - xbar);
*res = sum_1 + sum_2;
sum += xs[i] * xs[i];
*res = sum;
return 0;
}
......
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