changeset 9939:11aa2931dfc7

Make floorlog10 function more precise.
author Bruno Haible <bruno@clisp.org>
date Sat, 19 Apr 2008 17:55:05 +0200
parents 9f8c455639fc
children 0471a8660b70
files ChangeLog lib/vasnprintf.c
diffstat 2 files changed, 9 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2008-04-19  Bruno Haible  <bruno@clisp.org>
+
+	* lib/vasnprintf.c (floorlog10l, floorlog10): Reduce maximum error
+	from 0.0058 to less than 10^-7.
+
 2008-04-19  Bruno Haible  <bruno@clisp.org>
 
 	Fix rounding when a precision is given.
--- a/lib/vasnprintf.c
+++ b/lib/vasnprintf.c
@@ -1301,9 +1301,9 @@
     }
   /* Now 0.95 <= z <= 1.01.  */
   z = 1 - z;
-  /* log(1-z) = - z - z^2/2 - z^3/3 - z^4/4 - ...
+  /* log2(1-z) = 1/log(2) * (- z - z^2/2 - z^3/3 - z^4/4 - ...)
      Four terms are enough to get an approximation with error < 10^-7.  */
-  l -= z * (1.0 + z * (0.5 + z * ((1.0 / 3) + z * 0.25)));
+  l -= 1.4426950408889634074 * z * (1.0 + z * (0.5 + z * ((1.0 / 3) + z * 0.25)));
   /* Finally multiply with log(2)/log(10), yields an approximation for
      log10(x).  */
   l *= 0.30102999566398119523;
@@ -1392,9 +1392,9 @@
     }
   /* Now 0.95 <= z <= 1.01.  */
   z = 1 - z;
-  /* log(1-z) = - z - z^2/2 - z^3/3 - z^4/4 - ...
+  /* log2(1-z) = 1/log(2) * (- z - z^2/2 - z^3/3 - z^4/4 - ...)
      Four terms are enough to get an approximation with error < 10^-7.  */
-  l -= z * (1.0 + z * (0.5 + z * ((1.0 / 3) + z * 0.25)));
+  l -= 1.4426950408889634074 * z * (1.0 + z * (0.5 + z * ((1.0 / 3) + z * 0.25)));
   /* Finally multiply with log(2)/log(10), yields an approximation for
      log10(x).  */
   l *= 0.30102999566398119523;