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 a9cd1557cd21591e19c02b8605c9fd3e2c7231f0..87c3de2eba9c46dc724192dc1f66f66966539302 100644 (file)
--- 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.
index 2ee0c05ce6f882173aee214028563a56d417468c..fbf13c8ef82556a1660b5fcbf11e62b28a3cb803 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;