[gnumeric] Complex: use goffice's support.



commit 2ecc416d71d6a99debc1984c246c5448f23ac109
Author: Morten Welinder <terra gnome org>
Date:   Sun May 22 18:57:28 2011 -0400

    Complex: use goffice's support.
    
    Except for pow where we have the better implementation.

 ChangeLog     |    2 +
 NEWS          |    1 +
 src/complex.c |   76 ++----------------
 src/complex.h |  250 +++++++++++----------------------------------------------
 4 files changed, 59 insertions(+), 270 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 5a6b78c..731bc11 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
 2011-05-22  Morten Welinder  <terra gnome org>
 
+	* src/complex.h: Use goffice's stuff as far as possible.
+
 	* src/sheet-view.c (sv_is_region_empty_or_selected): Unused.  Remove.
 
 	* src/gnm-marshalers.list: Remove unused marshallers.
diff --git a/NEWS b/NEWS
index 6a0dd1e..3a2423d 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,7 @@ Morten:
 	* Fix leaks in SHEET.  [#650761]
 	* Fix leaks in SHEETS.  [#650764]
 	* Fix leak in name dialog.
+	* Switch to using goffice's complex math.
 
 --------------------------------------------------------------------------
 Gnumeric 1.10.15
diff --git a/src/complex.c b/src/complex.c
index 8bcf219..c4bc9ca 100644
--- a/src/complex.c
+++ b/src/complex.c
@@ -8,7 +8,6 @@
 
 #include <gnumeric-config.h>
 #include "gnumeric.h"
-#define GNUMERIC_COMPLEX_IMPLEMENTATION
 #include "complex.h"
 
 #include <stdlib.h>
@@ -139,73 +138,6 @@ complex_from_string (complex_t *dst, char const *src, char *imunit)
 
 /* ------------------------------------------------------------------------- */
 
-void
-complex_to_polar (gnm_float *mod, gnm_float *angle, complex_t const *src)
-{
-	*mod = complex_mod (src);
-	*angle = complex_angle (src);
-}
-
-/* ------------------------------------------------------------------------- */
-
-void
-complex_from_polar (complex_t *dst, gnm_float mod, gnm_float angle)
-{
-	complex_init (dst, mod * gnm_cos (angle), mod * gnm_sin (angle));
-}
-
-/* ------------------------------------------------------------------------- */
-
-void
-complex_mul (complex_t *dst, complex_t const *a, complex_t const *b)
-{
-	complex_init (dst,
-		      a->re * b->re - a->im * b->im,
-		      a->re * b->im + a->im * b->re);
-}
-
-/* ------------------------------------------------------------------------- */
-
-void
-complex_div (complex_t *dst, complex_t const *a, complex_t const *b)
-{
-	gnm_float bmod = complex_mod (b);
-
-	if (bmod >= GNM_const(1e10)) {
-		/* Ok, it's big.  */
-		gnm_float a_re = a->re / bmod;
-		gnm_float a_im = a->im / bmod;
-		gnm_float b_re = b->re / bmod;
-		gnm_float b_im = b->im / bmod;
-		complex_init (dst,
-			      a_re * b_re + a_im * b_im,
-			      a_im * b_re - a_re * b_im);
-	} else {
-		gnm_float bmodsqr = bmod * bmod;
-		complex_init (dst,
-			      (a->re * b->re + a->im * b->im) / bmodsqr,
-			      (a->im * b->re - a->re * b->im) / bmodsqr);
-	}
-}
-
-/* ------------------------------------------------------------------------- */
-
-void
-complex_sqrt (complex_t *dst, complex_t const *src)
-{
-	if (complex_real_p (src)) {
-		if (src->re >= 0)
-			complex_init (dst, gnm_sqrt (src->re), 0);
-		else
-			complex_init (dst, 0, gnm_sqrt (-src->re));
-	} else
-		complex_from_polar (dst,
-				    gnm_sqrt (complex_mod (src)),
-				    complex_angle (src) / 2);
-}
-
-/* ------------------------------------------------------------------------- */
-
 /* Like complex_angle, but divide result by pi.  */
 static gnm_float
 complex_angle_pi (complex_t const *src)
@@ -267,3 +199,11 @@ complex_pow (complex_t *dst, complex_t const *a, complex_t const *b)
 }
 
 /* ------------------------------------------------------------------------- */
+
+int
+complex_invalid_p (complex_t const *src)
+{
+	return !(gnm_finite (src->re) && gnm_finite (src->im));
+}
+
+/* ------------------------------------------------------------------------- */
diff --git a/src/complex.h b/src/complex.h
index ba3e0fe..f4385e1 100644
--- a/src/complex.h
+++ b/src/complex.h
@@ -3,36 +3,58 @@
 # define _GNM_COMPLEX_H_
 
 #include "numbers.h"
+#include <goffice/goffice.h>
 #include <math.h>
 
 G_BEGIN_DECLS
 
-typedef struct {
-	gnm_float re, im;
-} complex_t;
-
-#ifdef GNUMERIC_COMPLEX_IMPLEMENTATION
-
-/* The actual definitions.  */
-#define GNUMERIC_COMPLEX_PROTO(p) p; p
-#define GNUMERIC_COMPLEX_BODY
-
+#ifdef GNM_WITH_LONG_DOUBLE
+typedef go_complexl complex_t;
+#define complex_init go_complex_initl
+#define complex_add go_complex_addl
+#define complex_sub go_complex_subl
+#define complex_mul go_complex_mull
+#define complex_div go_complex_divl
+#define complex_mod go_complex_modl
+#define complex_angle go_complex_anglel
+#define complex_real go_complex_reall
+#define complex_real_p go_complex_real_pl
+#define complex_zero_p go_complex_zero_pl
+#define complex_conj go_complex_conjl
+#define complex_exp go_complex_expl
+#define complex_ln go_complex_lnl
+#define complex_sqrt go_complex_sqrtl
+#define complex_sin go_complex_sinl
+#define complex_cos go_complex_cosl
+#define complex_tan go_complex_tanl
+#define complex_scale_real go_complex_scale_reall
+#define complex_to_polar go_complex_to_polarl
+#define complex_from_polar go_complex_from_polarl
 #else
-
-#ifdef __GNUC__
-
-/* Have gcc -- inline functions.  */
-#define GNUMERIC_COMPLEX_PROTO(p) p; extern __inline__ p
-#define GNUMERIC_COMPLEX_BODY
-
-#else
-
-/* No gcc -- no inline functions.  */
-#define GNUMERIC_COMPLEX_PROTO(p) extern p;
-#undef GNUMERIC_COMPLEX_BODY
-
-#endif
-#endif
+typedef go_complex complex_t;
+#define complex_init go_complex_init
+#define complex_add go_complex_add
+#define complex_sub go_complex_sub
+#define complex_mul go_complex_mul
+#define complex_div go_complex_div
+#define complex_mod go_complex_mod
+#define complex_angle go_complex_angle
+#define complex_real go_complex_real
+#define complex_real_p go_complex_real_p
+#define complex_zero_p go_complex_zero_p
+#define complex_conj go_complex_conj
+#define complex_exp go_complex_exp
+#define complex_ln go_complex_ln
+#define complex_sqrt go_complex_sqrt
+#define complex_sin go_complex_sin
+#define complex_cos go_complex_cos
+#define complex_tan go_complex_tan
+#define complex_scale_real go_complex_scale_real
+#define complex_to_polar go_complex_to_polar
+#define complex_from_polar go_complex_from_polar
+#endif
+
+#define complex_invalid(c_) complex_init((c_),gnm_nan,gnm_nan)
 
 /* ------------------------------------------------------------------------- */
 
@@ -41,187 +63,11 @@ char *complex_to_string (complex_t const *src, char const *reformat,
 
 int complex_from_string (complex_t *dst, char const *src, char *imunit);
 
-void complex_to_polar (gnm_float *mod, gnm_float *angle, complex_t const *src);
-void complex_from_polar (complex_t *dst, gnm_float mod, gnm_float angle);
-void complex_mul  (complex_t *dst, complex_t const *a, complex_t const *b);
-void complex_div  (complex_t *dst, complex_t const *a, complex_t const *b);
 void complex_pow  (complex_t *dst, complex_t const *a, complex_t const *b);
-void complex_sqrt (complex_t *dst, complex_t const *src);
+int complex_invalid_p (complex_t const *src);
 
 /* ------------------------------------------------------------------------- */
 
-GNUMERIC_COMPLEX_PROTO (void complex_init (complex_t *dst, gnm_float re, gnm_float im))
-#ifdef GNUMERIC_COMPLEX_BODY
-{
-	dst->re = re;
-	dst->im = im;
-}
-#endif
-
-/* ------------------------------------------------------------------------- */
-
-GNUMERIC_COMPLEX_PROTO (void complex_invalid (complex_t *dst))
-#ifdef GNUMERIC_COMPLEX_BODY
-{
-	dst->re = gnm_nan;
-	dst->im = gnm_nan;
-}
-#endif
-
-/* ------------------------------------------------------------------------- */
-
-GNUMERIC_COMPLEX_PROTO (void complex_real (complex_t *dst, gnm_float re))
-#ifdef GNUMERIC_COMPLEX_BODY
-{
-	dst->re = re;
-	dst->im = 0;
-}
-#endif
-
-/* ------------------------------------------------------------------------- */
-
-GNUMERIC_COMPLEX_PROTO (int complex_real_p (complex_t const *src))
-#ifdef GNUMERIC_COMPLEX_BODY
-{
-	return src->im == 0;
-}
-#endif
-
-/* ------------------------------------------------------------------------- */
-
-GNUMERIC_COMPLEX_PROTO (int complex_invalid_p (complex_t const *src))
-#ifdef GNUMERIC_COMPLEX_BODY
-{
-	return !(gnm_finite (src->re) && gnm_finite (src->im));
-}
-#endif
-
-/* ------------------------------------------------------------------------- */
-
-GNUMERIC_COMPLEX_PROTO (int complex_zero_p (complex_t const *src))
-#ifdef GNUMERIC_COMPLEX_BODY
-{
-	return src->re == 0 && src->im == 0;
-}
-#endif
-
-/* ------------------------------------------------------------------------- */
-
-GNUMERIC_COMPLEX_PROTO (gnm_float complex_mod (complex_t const *src))
-#ifdef GNUMERIC_COMPLEX_BODY
-{
-	return gnm_hypot (src->re, src->im);
-}
-#endif
-
-/* ------------------------------------------------------------------------- */
-
-GNUMERIC_COMPLEX_PROTO (gnm_float complex_angle (complex_t const *src))
-#ifdef GNUMERIC_COMPLEX_BODY
-{
-	return gnm_atan2 (src->im, src->re);
-}
-#endif
-
-/* ------------------------------------------------------------------------- */
-
-GNUMERIC_COMPLEX_PROTO (void complex_conj (complex_t *dst, complex_t const *src))
-#ifdef GNUMERIC_COMPLEX_BODY
-{
-	complex_init (dst, src->re, -src->im);
-}
-#endif
-
-/* ------------------------------------------------------------------------- */
-
-GNUMERIC_COMPLEX_PROTO (void complex_scale_real (complex_t *dst, gnm_float f))
-#ifdef GNUMERIC_COMPLEX_BODY
-{
-	dst->re *= f;
-	dst->im *= f;
-}
-#endif
-
-/* ------------------------------------------------------------------------- */
-
-GNUMERIC_COMPLEX_PROTO (void complex_add (complex_t *dst, complex_t const *a, complex_t const *b))
-#ifdef GNUMERIC_COMPLEX_BODY
-{
-	complex_init (dst, a->re + b->re, a->im + b->im);
-}
-#endif
-
-/* ------------------------------------------------------------------------- */
-
-GNUMERIC_COMPLEX_PROTO (void complex_sub (complex_t *dst, complex_t const *a, complex_t const *b))
-#ifdef GNUMERIC_COMPLEX_BODY
-{
-	complex_init (dst, a->re - b->re, a->im - b->im);
-}
-#endif
-
-/* ------------------------------------------------------------------------- */
-
-GNUMERIC_COMPLEX_PROTO (void complex_exp (complex_t *dst, complex_t const *src))
-#ifdef GNUMERIC_COMPLEX_BODY
-{
-	complex_init (dst,
-		      gnm_exp (src->re) * gnm_cos (src->im),
-		      gnm_exp (src->re) * gnm_sin (src->im));
-}
-#endif
-
-/* ------------------------------------------------------------------------- */
-
-GNUMERIC_COMPLEX_PROTO (void complex_ln (complex_t *dst, complex_t const *src))
-#ifdef GNUMERIC_COMPLEX_BODY
-{
-	complex_init (dst,
-		      gnm_log (complex_mod (src)),
-		      complex_angle (src));
-}
-#endif
-
-/* ------------------------------------------------------------------------- */
-
-GNUMERIC_COMPLEX_PROTO (void complex_sin (complex_t *dst, complex_t const *src))
-#ifdef GNUMERIC_COMPLEX_BODY
-{
-	complex_init (dst,
-		      gnm_sin (src->re) * gnm_cosh (src->im),
-		      gnm_cos (src->re) * gnm_sinh (src->im));
-}
-#endif
-
-/* ------------------------------------------------------------------------- */
-
-GNUMERIC_COMPLEX_PROTO (void complex_cos (complex_t *dst, complex_t const *src))
-#ifdef GNUMERIC_COMPLEX_BODY
-{
-	complex_init (dst,
-		      gnm_cos (src->re) * gnm_cosh (src->im),
-		      -gnm_sin (src->re) * gnm_sinh (src->im));
-}
-#endif
-
-/* ------------------------------------------------------------------------- */
-
-GNUMERIC_COMPLEX_PROTO (void complex_tan (complex_t *dst, complex_t const *src))
-#ifdef GNUMERIC_COMPLEX_BODY
-{
-	complex_t s, c;
-
-	complex_sin (&s, src);
-	complex_cos (&c, src);
-	complex_div (dst, &s, &c);
-}
-#endif
-
-/* ------------------------------------------------------------------------- */
-
-#undef GNUMERIC_COMPLEX_PROTO
-#undef GNUMERIC_COMPLEX_BODY
-
 G_END_DECLS
 
 #endif /* _GNM_COMPLEX_H_ */



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