[gnumeric] agm: minor code rearrangement.



commit c658f6d8a528c47041b841d11b76d8014352f754
Author: Morten Welinder <terra gnome org>
Date:   Sun Nov 18 11:48:00 2018 -0500

    agm: minor code rearrangement.
    
    Handle the a==b case early.  No need for iteration.

 ChangeLog      |  5 +++++
 src/mathfunc.c | 12 +++++++-----
 2 files changed, 12 insertions(+), 5 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 678ea9a30..162cac103 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2018-11-18  Morten Welinder  <terra gnome org>
+
+       * src/mathfunc.c (gnm_agm): Short-circuit the a==b case early.  We
+       only need it for +inf, but it's valid and meaningful for all values.
+
 2018-11-17  Morten Welinder  <terra gnome org>
 
        * src/gui-util.c (gnm_create_popup_menu): Use a
diff --git a/src/mathfunc.c b/src/mathfunc.c
index f8546def1..c04106dd2 100644
--- a/src/mathfunc.c
+++ b/src/mathfunc.c
@@ -4990,14 +4990,16 @@ gnm_agm (gnm_float a, gnm_float b)
        if (a < 0 || b < 0 || gnm_isnan (ab))
                return gnm_nan;
 
-       if (a == gnm_pinf || b == gnm_pinf)
-               return gnm_pinf;
-       if (a == 0 || b == 0)
-               return 0;
+       if (a == b)
+               return a;
 
        if (ab == 0 || ab == gnm_pinf) {
-               // Underflow or overflow
                int ea, eb;
+
+               if (a == 0 || b == 0)
+                       return 0;
+
+               // Underflow or overflow
                (void)gnm_frexp (a, &ea);
                (void)gnm_frexp (b, &eb);
                scale = gnm_ldexp (1, -(ea + eb) / 2);


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