[goffice] Complex: fix overflow in complex power.



commit b89590989b2966db94401c4bec7be4b59e4fafbe
Author: Morten Welinder <terra gnome org>
Date:   Wed Dec 4 16:43:01 2013 -0500

    Complex: fix overflow in complex power.

 ChangeLog                 |    5 +++++
 NEWS                      |    4 ++++
 goffice/math/go-complex.c |    9 +++++++--
 3 files changed, 16 insertions(+), 2 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 0136ab4..6a329f4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2013-12-04  Morten Welinder  <terra gnome org>
+
+       * goffice/math/go-complex.c (go_complex_pow): Fix class over
+       premature overflow problems.
+
 2013-12-02  Jean Brefort  <jean brefort normalesup org>
 
        reviewed by: <delete if not using a buddy>
diff --git a/NEWS b/NEWS
index ba45086..0f1107f 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,10 @@ goffice 0.10.10:
 
 Jean
        * Fix graph guru appearance when used with gtk+-3.10. [#719681]
+
+Morten:
+       * Improve complex math.
+
 --------------------------------------------------------------------------
 goffice 0.10.9:
 
diff --git a/goffice/math/go-complex.c b/goffice/math/go-complex.c
index c46fc4f..afe7d40 100644
--- a/goffice/math/go-complex.c
+++ b/goffice/math/go-complex.c
@@ -254,11 +254,16 @@ SUFFIX(go_complex_pow) (SUFFIX(GOComplex) *dst, SUFFIX(GOComplex) const *a, SUFF
                else
                        SUFFIX(go_complex_real) (dst, 0);
        } else {
-               DOUBLE res_r, res_a1, res_a2, res_a2_pi, r, arg;
+               DOUBLE res_r, res_a1, res_a2, res_a2_pi, r, rre, arg;
                SUFFIX(GOComplex) F;
 
                SUFFIX(go_complex_to_polar) (&r, &arg, a);
-               res_r = SUFFIX(pow) (r, b->re) * SUFFIX(exp) (-b->im * arg);
+               /*
+                * This is the square root of the power we really want,
+                * but it is much less likely to cause overflow.
+                */
+               rre = SUFFIX(pow) (r, b->re / 2);
+               res_r = rre * SUFFIX(exp) (-b->im * arg) * rre;
                res_a1 = b->im * SUFFIX(log) (r);
                res_a2 = b->re * arg;
                res_a2_pi = b->re * SUFFIX(go_complex_angle_pi) (a);


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