Make floorlog10 function more precise.
authorBruno Haible <bruno@clisp.org>
Sat, 19 Apr 2008 15:55:05 +0000 (17:55 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 19 Apr 2008 15:55:05 +0000 (17:55 +0200)
ChangeLog
lib/vasnprintf.c

index a9cd155..87c3de2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 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.
        * lib/vasnprintf.c (is_borderline): New function.
        (VASNPRINTF): For %e and %g, consider replacing the digits 10....0 with
index 2ee0c05..fbf13c8 100644 (file)
@@ -1301,9 +1301,9 @@ floorlog10l (long double x)
     }
   /* 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 @@ floorlog10 (double x)
     }
   /* 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;