[gnumeric] LOG2: Improve accuracy.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] LOG2: Improve accuracy.
- Date: Wed, 19 Feb 2014 19:04:21 +0000 (UTC)
commit 7ba9593d9768e2a94e444ecdeea11931b7d7975b
Author: Morten Welinder <terra gnome org>
Date: Wed Feb 19 14:04:05 2014 -0500
LOG2: Improve accuracy.
ChangeLog | 6 ++++++
NEWS | 1 +
plugins/fn-math/functions.c | 2 +-
src/mathfunc.c | 19 +++++++++++++++++++
src/mathfunc.h | 1 +
5 files changed, 28 insertions(+), 1 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index cc41852..548461e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2014-02-19 Morten Welinder <terra gnome org>
+
+ * plugins/fn-math/functions.c (gnumeric_log2): Use gnm_log2.
+
+ * src/mathfunc.c (gnm_log2): New function.
+
2014-02-18 Morten Welinder <terra gnome org>
* src/ssdiff.c (xml_style_changed): Report differences for
diff --git a/NEWS b/NEWS
index c40cfda..691a40a 100644
--- a/NEWS
+++ b/NEWS
@@ -14,6 +14,7 @@ Morten:
* Improve testing.
* Fix XLSX number roundtrip issues. [?] and [#724661]
* Improve ssdiff's report of differences.
+ * Improve LOG2's accuracy.
--------------------------------------------------------------------------
Gnumeric 1.12.11
diff --git a/plugins/fn-math/functions.c b/plugins/fn-math/functions.c
index bc49553..b3c95af 100644
--- a/plugins/fn-math/functions.c
+++ b/plugins/fn-math/functions.c
@@ -1325,7 +1325,7 @@ gnumeric_log2 (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
if (t <= 0.0)
return value_new_error_NUM (ei->pos);
- return value_new_float (gnm_log (t) / M_LN2gnum);
+ return value_new_float (gnm_log2 (t));
}
/***************************************************************************/
diff --git a/src/mathfunc.c b/src/mathfunc.c
index 1b5ca50..3efa808 100644
--- a/src/mathfunc.c
+++ b/src/mathfunc.c
@@ -311,6 +311,25 @@ bd0(gnm_float x, gnm_float M)
return yh + yl;
}
+gnm_float
+gnm_log2 (gnm_float x)
+{
+ int e;
+
+ if (x == 0)
+ return gnm_ninf;
+
+ if (x < 0)
+ return gnm_nan;
+
+ if (!gnm_finite (x))
+ return x;
+
+ /* This split ensures accurate integer results for 2^x. */
+ x = gnm_frexp (x, &e);
+
+ return e + gnm_log (x) / M_LN2gnum;
+}
/* ------------------------------------------------------------------------- */
/* --- BEGIN MAGIC R SOURCE MARKER --- */
diff --git a/src/mathfunc.h b/src/mathfunc.h
index e24fa05..d86d162 100644
--- a/src/mathfunc.h
+++ b/src/mathfunc.h
@@ -27,6 +27,7 @@ G_BEGIN_DECLS
/* ------------------------------------------------------------------------- */
+gnm_float gnm_log2 (gnm_float x);
gnm_float log1pmx (gnm_float x);
gnm_float swap_log_tail (gnm_float lp);
gnm_float pow1p (gnm_float x, gnm_float y);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]