[goffice] Quad: fix hypot.



commit 444c6bdd1aba1ff26ecc472ee4762cd896ced9c5
Author: Morten Welinder <terra gnome org>
Date:   Mon Dec 16 20:08:58 2013 -0500

    Quad: fix hypot.

 ChangeLog              |    6 ++++++
 goffice/math/go-quad.c |    6 ++++--
 tests/test-quad.c      |   37 +++++++++++++++++++++++++++++++++++++
 3 files changed, 47 insertions(+), 2 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 1827265..4c90f66 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2013-12-16  Morten Welinder  <terra gnome org>
+
+       * tests/test-quad.c (main): Test hypot.
+
+       * goffice/math/go-quad.c: Fix the on-axis case.  *Sigh*
+
 2013-12-13  Jean Brefort  <jean brefort normalesup org>
 
        * plugins/plot_radar/gog-radar.c (gog_rt_series_update): fix elements
diff --git a/goffice/math/go-quad.c b/goffice/math/go-quad.c
index 2b2f114..8e9c520 100644
--- a/goffice/math/go-quad.c
+++ b/goffice/math/go-quad.c
@@ -930,11 +930,13 @@ SUFFIX(go_quad_hypot) (QUAD *res, const QUAD *a, const QUAD *b)
        QUAD qa2, qb2, qn;
 
        if (a->h == 0) {
-               *res = *b;
+               res->h = SUFFIX(fabs)(b->h);
+               res->l = SUFFIX(fabs)(b->l);
                return;
        }
        if (b->h == 0) {
-               *res = *a;
+               res->h = SUFFIX(fabs)(a->h);
+               res->l = SUFFIX(fabs)(a->l);
                return;
        }
 
diff --git a/tests/test-quad.c b/tests/test-quad.c
index 943770d..e564b09 100644
--- a/tests/test-quad.c
+++ b/tests/test-quad.c
@@ -126,6 +126,42 @@ atan2_tests (void)
 
 /* ------------------------------------------------------------------------- */
 
+static void
+hypot_tests (void)
+{
+#define TEST1(a_,b_) BINTEST1(a_,b_,go_quad_hypot,hypot,"hypot");
+       TEST1 (0, +2);
+       TEST1 (0, -2);
+       TEST1 (3, 0);
+       TEST1 (-3, 0);
+       TEST1 (0, 0);
+       TEST1 (+1, +1);
+       TEST1 (+2.3, +1.2);
+       TEST1 (+2.3, -1.2);
+       TEST1 (+2.3, +0.2);
+       TEST1 (+2.3, -0.2);
+       TEST1 (+0.2, +2.3);
+       TEST1 (+0.2, -2.3);
+       TEST1 (+2.3, +3);
+       TEST1 (+2.3, -3);
+       TEST1 (-2.3, +3);
+       TEST1 (-2.3, -3);
+       TEST1 (+2.3, +4);
+       TEST1 (+2.3, -4);
+       TEST1 (-2.3, +4);
+       TEST1 (-2.3, -4);
+       TEST1 (2, 100);
+       TEST1 (2, -100);
+       TEST1 (1.0/256, 1.0/1024);
+       TEST1 (exp(1), 1);
+       TEST1 (exp(1), -1);
+       TEST1 (exp(1), log(2));
+       TEST1 (exp(1), -log(2));
+}
+#undef TEST1
+
+/* ------------------------------------------------------------------------- */
+
 #define TEST1(a_,b_)                           \
 do {                                           \
        BINTEST1(a_,b_,go_quad_add,ADD,"add");  \
@@ -290,6 +326,7 @@ main (int argc, char **argv)
        pow_tests ();
        floor_tests ();
        atan2_tests ();
+       hypot_tests ();
 
        go_quad_end (state);
 


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