summary refs log tree commit diff
path: root/stdio-common
diff options
context:
space:
mode:
Diffstat (limited to 'stdio-common')
-rw-r--r--stdio-common/printf_fp.c13
-rw-r--r--stdio-common/tfformat.c19
2 files changed, 30 insertions, 2 deletions
diff --git a/stdio-common/printf_fp.c b/stdio-common/printf_fp.c
index 5cf60f131c..009bdee0d5 100644
--- a/stdio-common/printf_fp.c
+++ b/stdio-common/printf_fp.c
@@ -625,11 +625,22 @@ __printf_fp (FILE *fp,
       /* All factors but 10^-1 are tested now.	*/
       if (exponent > 0)
 	{
+	  int cnt_l;
+
 	  cy = __mpn_mul_1 (tmp, frac, fracsize, 10);
 	  tmpsize = fracsize;
 	  assert (cy == 0 || tmp[tmpsize - 1] < 20);
 
-	  (void) __mpn_rshift (frac, tmp, tmpsize, MIN (4, exponent));
+	  count_trailing_zeros (cnt_l, tmp[0]);
+	  if (cnt_l < MIN (4, exponent))
+	    {
+	      cy = __mpn_lshift (frac, tmp, tmpsize,
+				 BITS_PER_MP_LIMB - MIN (4, exponent));
+	      if (cy != 0)
+		frac[tmpsize++] = cy;
+	    }
+	  else
+	    (void) __mpn_rshift (frac, tmp, tmpsize, MIN (4, exponent));
 	  fracsize = tmpsize;
 	  exp10 |= 1;
 	  assert (frac[fracsize - 1] < 10);
diff --git a/stdio-common/tfformat.c b/stdio-common/tfformat.c
index 02230f11ba..60785d803f 100644
--- a/stdio-common/tfformat.c
+++ b/stdio-common/tfformat.c
@@ -10,7 +10,7 @@ typedef struct
   const char *format_string;
 } sprint_double_type;
 
-sprint_double_type sprint_doubles[] = 
+sprint_double_type sprint_doubles[] =
 {
 __LINE__,  30.3,			"<          +30.3>", "<%+15.10g>",
 __LINE__,  10.0,			"<10.00>", "<%5.2f>",
@@ -4071,6 +4071,23 @@ int main()
       testcount++;
     }
 
+  /* And one special test.  */
+  {
+    const char ref[] = "1.7763568394002504646778106689453125e-15";
+    int i;
+    d = 1.0;
+    for (i = 1; i < 50; ++i)
+      d /= 2;
+    sprintf (buffer, "%.100g", d);
+    if (!matches (buffer, ref))
+      {
+	++errcount;
+	printf (
+    "Error in line %d using \"%s\".  Result is \"%s\"; should be: \"%s\".\n",
+		__LINE__, "%.100g", buffer, ref);
+      }
+  }
+
   if (errcount == 0)
     {
       printf("Encountered no errors in %d tests.\n", testcount);