[goffice] Math: minor accumulator improvements.



commit 4e5d06dc3dbb532a034f0135eb3c527e8091c79e
Author: Morten Welinder <terra gnome org>
Date:   Fri Nov 25 13:46:32 2011 -0500

    Math: minor accumulator improvements.

 ChangeLog                     |    8 ++++++++
 goffice/math/go-accumulator.c |   16 +++++++++++-----
 goffice/math/go-accumulator.h |    6 ++----
 goffice/math/go-quad.c        |    2 +-
 goffice/math/go-quad.h        |    8 ++++----
 goffice/math/go-rangefunc.c   |   15 +++++----------
 goffice/math/goffice-math.h   |    9 +++++++++
 7 files changed, 40 insertions(+), 24 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index fe389ac..468ac4b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2011-11-25  Morten Welinder  <terra gnome org>
+
+	* goffice/math/go-rangefunc.c (go_range_sumsq, go_range_devsq):
+	Simplify.
+
+	* goffice/math/go-accumulator.c (go_accumulator_add_quad): New
+	function.
+
 2011-11-24  Morten Welinder <terra gnome org>
 
 	* configure.in: Post-release bump.
diff --git a/goffice/math/go-accumulator.c b/goffice/math/go-accumulator.c
index a9d44aa..9733a05 100644
--- a/goffice/math/go-accumulator.c
+++ b/goffice/math/go-accumulator.c
@@ -15,8 +15,7 @@
  */
 
 #include <goffice/goffice-config.h>
-#include "go-accumulator.h"
-#include "go-quad.h"
+#include <goffice/goffice.h>
 #include <math.h>
 #include <float.h>
 
@@ -24,7 +23,6 @@
 
 #define DOUBLE double
 #define SUFFIX(_n) _n
-#define DOUBLE_MANT_DIG DBL_MANT_DIG
 
 struct GOAccumulator_ {
 	GArray *partials;
@@ -35,10 +33,8 @@ struct GOAccumulator_ {
 #include "go-accumulator.c"
 #undef DOUBLE
 #undef SUFFIX
-#undef DOUBLE_MANT_DIG
 #define DOUBLE long double
 #define SUFFIX(_n) _n ## l
-#define DOUBLE_MANT_DIG LDBL_MANT_DIG
 
 struct GOAccumulatorl_ {
 	GArray *partials;
@@ -119,6 +115,16 @@ SUFFIX(go_accumulator_add) (ACC *acc, DOUBLE x)
 	g_array_index (acc->partials, DOUBLE, ui) = x;
 }
 
+void
+SUFFIX(go_accumulator_add_quad) (ACC *acc, const SUFFIX(GOQuad) *x)
+{
+	g_return_if_fail (acc != NULL);
+	g_return_if_fail (x != NULL);
+
+	SUFFIX(go_accumulator_add) (acc, x->h);
+	SUFFIX(go_accumulator_add) (acc, x->l);
+}
+
 DOUBLE
 SUFFIX(go_accumulator_value) (ACC *acc)
 {
diff --git a/goffice/math/go-accumulator.h b/goffice/math/go-accumulator.h
index 1b25d96..43e9b3e 100644
--- a/goffice/math/go-accumulator.h
+++ b/goffice/math/go-accumulator.h
@@ -5,8 +5,6 @@
 
 G_BEGIN_DECLS
 
-typedef struct GOAccumulator_ GOAccumulator;
-
 gboolean go_accumulator_functional (void);
 void *go_accumulator_start (void);
 void go_accumulator_end (void *state);
@@ -15,13 +13,12 @@ GOAccumulator *go_accumulator_new (void);
 void go_accumulator_free (GOAccumulator *acc);
 void go_accumulator_clear (GOAccumulator *acc);
 void go_accumulator_add (GOAccumulator *acc, double x);
+void go_accumulator_add_quad (GOAccumulator *acc, const GOQuad *x);
 double go_accumulator_value (GOAccumulator *acc);
 
 
 #ifdef GOFFICE_WITH_LONG_DOUBLE
 
-typedef struct GOAccumulatorl_ GOAccumulatorl;
-
 gboolean go_accumulator_functionall (void);
 void *go_accumulator_startl (void);
 void go_accumulator_endl (void *state);
@@ -30,6 +27,7 @@ GOAccumulatorl *go_accumulator_newl (void);
 void go_accumulator_freel (GOAccumulatorl *acc);
 void go_accumulator_clearl (GOAccumulatorl *acc);
 void go_accumulator_addl (GOAccumulatorl *acc, long double x);
+void go_accumulator_add_quadl (GOAccumulatorl *acc, const GOQuadl *x);
 long double go_accumulator_valuel (GOAccumulatorl *acc);
 #endif
 
diff --git a/goffice/math/go-quad.c b/goffice/math/go-quad.c
index ba87492..a2008a7 100644
--- a/goffice/math/go-quad.c
+++ b/goffice/math/go-quad.c
@@ -17,7 +17,7 @@
  */
 
 #include <goffice/goffice-config.h>
-#include "go-quad.h"
+#include <goffice/goffice.h>
 #include <math.h>
 
 /* Normalize cpu id.  */
diff --git a/goffice/math/go-quad.h b/goffice/math/go-quad.h
index afa612b..b3be8a4 100644
--- a/goffice/math/go-quad.h
+++ b/goffice/math/go-quad.h
@@ -5,10 +5,10 @@
 
 G_BEGIN_DECLS
 
-typedef struct {
+struct GOQuad_ {
 	double h;
 	double l;
-} GOQuad;
+};
 
 gboolean go_quad_functional (void);
 void *go_quad_start (void);
@@ -28,10 +28,10 @@ void go_quad_mul12 (GOQuad *res, double x, double y);
 void go_quad_dot_product (GOQuad *res, const GOQuad *a, const GOQuad *b, int n);
 
 #ifdef GOFFICE_WITH_LONG_DOUBLE
-typedef struct {
+struct GOQuadl_ {
 	long double h;
 	long double l;
-} GOQuadl;
+};
 
 gboolean go_quad_functionall (void);
 void *go_quad_startl (void);
diff --git a/goffice/math/go-rangefunc.c b/goffice/math/go-rangefunc.c
index 70e2eae..83880b7 100644
--- a/goffice/math/go-rangefunc.c
+++ b/goffice/math/go-rangefunc.c
@@ -7,9 +7,7 @@
  */
 
 #include <goffice/goffice-config.h>
-#include "go-rangefunc.h"
-#include "go-accumulator.h"
-#include "go-quad.h"
+#include <goffice/goffice.h>
 
 #include <math.h>
 #include <stdlib.h>
@@ -75,12 +73,10 @@ SUFFIX(go_range_sumsq) (DOUBLE const *xs, int n, DOUBLE *res)
 	void *state = SUFFIX(go_accumulator_start) ();
 	SUFFIX(GOAccumulator) *acc = SUFFIX(go_accumulator_new) ();
 	while (n > 0) {
+		DOUBLE x = xs[--n];
 		SUFFIX(GOQuad) q;
-		n--;
-		SUFFIX(go_quad_init) (&q, xs[n]);
-		SUFFIX(go_quad_mul) (&q, &q, &q);
-		SUFFIX(go_accumulator_add) (acc, q.h);
-		SUFFIX(go_accumulator_add) (acc, q.l);
+		SUFFIX(go_quad_mul12) (&q, x, x);
+		SUFFIX(go_accumulator_add_quad) (acc, &q);
 	}
 	*res = SUFFIX(go_accumulator_value) (acc);
 	SUFFIX(go_accumulator_free) (acc);
@@ -195,8 +191,7 @@ SUFFIX(go_range_devsq) (DOUBLE const *xs, int n, DOUBLE *res)
 			SUFFIX(go_quad_init) (&q, xs[n]);
 			SUFFIX(go_quad_sub) (&q, &q, &qavg);
 			SUFFIX(go_quad_mul) (&q, &q, &q);
-			SUFFIX(go_accumulator_add) (acc, q.h);
-			SUFFIX(go_accumulator_add) (acc, q.l);
+			SUFFIX(go_accumulator_add_quad) (acc, &q);
 		}
 		*res = SUFFIX(go_accumulator_value) (acc);
 		SUFFIX(go_accumulator_free) (acc);
diff --git a/goffice/math/goffice-math.h b/goffice/math/goffice-math.h
index d0ae6f0..66be62f 100644
--- a/goffice/math/goffice-math.h
+++ b/goffice/math/goffice-math.h
@@ -1,6 +1,15 @@
 #ifndef __GOFFICE_MATH_H
 #define __GOFFICE_MATH_H
 
+/* Forward stuff */
+typedef struct GOAccumulator_ GOAccumulator;
+typedef struct GOQuad_ GOQuad;
+
+#ifdef GOFFICE_WITH_LONG_DOUBLE
+typedef struct GOAccumulatorl_ GOAccumulatorl;
+typedef struct GOQuadl_ GOQuadl;
+#endif
+
 #include <goffice/math/go-accumulator.h>
 #include <goffice/math/go-complex.h>
 #include <goffice/math/go-cspline.h>



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