[gnumeric] LOG: Improve accuracy when base argument is present.



commit a363bf32d664b07ff1f442b6db80908a8abecb43
Author: Morten Welinder <terra gnome org>
Date:   Wed Feb 19 14:08:50 2014 -0500

    LOG: Improve accuracy when base argument is present.

 ChangeLog                   |    1 +
 plugins/fn-math/functions.c |   12 +++++++++++-
 2 files changed, 12 insertions(+), 1 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 548461e..4cda3c3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,7 @@
 2014-02-19  Morten Welinder  <terra gnome org>
 
        * plugins/fn-math/functions.c (gnumeric_log2): Use gnm_log2.
+       (gnumeric_log): Use gnm_log2 and gnm_log10 as appropriate.
 
        * src/mathfunc.c (gnm_log2): New function.
 
diff --git a/plugins/fn-math/functions.c b/plugins/fn-math/functions.c
index b3c95af..5dceb59 100644
--- a/plugins/fn-math/functions.c
+++ b/plugins/fn-math/functions.c
@@ -1186,6 +1186,7 @@ gnumeric_log (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
 {
        gnm_float t = value_get_as_float (argv[0]);
        gnm_float base = argv[1] ? value_get_as_float (argv[1]) : 10;
+       gnm_float res;
 
        if (base == 1. || base <= 0.)
                return value_new_error_NUM (ei->pos);
@@ -1193,7 +1194,16 @@ gnumeric_log (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
        if (t <= 0.0)
                return value_new_error_NUM (ei->pos);
 
-       return value_new_float (gnm_log (t) / gnm_log (base));
+       if (base == 2)
+               res = gnm_log2 (t);
+       else if (base == 0.5)
+               res = -gnm_log2 (t);
+       else if (base == 10)
+               res = gnm_log10 (t);
+       else
+               res = gnm_log (t) / gnm_log (base);
+
+       return value_new_float (res);
 }
 
 /***************************************************************************/


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