]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - stdio-common/tfformat.c
Improve documentation for malloc etc. (BZ#27719)
[thirdparty/glibc.git] / stdio-common / tfformat.c
index ea7365b2c99ed38858fe74356fc5d875460cc387..4eb47f0c2b94080ae5559a1bb6f9636287546290 100644 (file)
@@ -1,3 +1,4 @@
+#include <math.h>
 #include <stdio.h>
 
 /* Tests taken from Cygnus C library. */
@@ -4009,9 +4010,62 @@ sprint_double_type sprint_doubles[] =
   {__LINE__, 11.25,                    "11.2", "%.1f"},
   {__LINE__, 1.75,                     "1.8", "%.1f"},
   {__LINE__, 11.75,                    "11.8", "%.1f"},
+  {__LINE__, -1.25,                    "-1.2", "%.1f"},
+  {__LINE__, -11.25,                   "-11.2", "%.1f"},
+  {__LINE__, -1.75,                    "-1.8", "%.1f"},
+  {__LINE__, -11.75,                   "-11.8", "%.1f"},
   {__LINE__, 16,                       "0x1.0p+4", "%.1a"},
   {__LINE__, 16,                       "0x1.00000000000000000000p+4", "%.20a"},
   {__LINE__, 4444.88888888,            "4445", "%2.F"},
+  {__LINE__, 0.956,                    "1", "%.0g"},
+  {__LINE__, 1.0956,                   "1.", "%#.0g"},
+  {__LINE__, 0.956,                    "1.", "%#.0g"},
+  {__LINE__, 0.0956,                   "0.1", "%#.0g"},
+  {__LINE__, 0.00956,                  "0.01", "%#.0g"},
+  {__LINE__, 0.000956,                 "0.001", "%#.0g"},
+  {__LINE__, 0.000098,                 "0.0001", "%#.0g"},
+  {__LINE__, 0.0000996,                        "0.00010", "%#.2g"},
+  {__LINE__, 9.999999999999999e-05,    "0.0001", "%g"},
+  {__LINE__, 1.0,                      "1.000000e+00", "%e"},
+  {__LINE__, .9999999999999999,                "1.000000e+00", "%e"},
+
+  {__LINE__, 912.98,                   "913.0", "%#.4g"},
+  {__LINE__, 50.999999,                        "51.000", "%#.5g"},
+  {__LINE__, 0.956,                    "1", "%.1g"},
+  {__LINE__, 0.956,                    "1.", "%#.1g"},
+  {__LINE__, 0.996,                    "1", "%.2g"},
+  {__LINE__, 0.996,                    "1.0", "%#.2g"},
+  {__LINE__, 999.98,                   "1000", "%.4g"},
+  {__LINE__, 999.98,                   "1000.", "%#.4g"},
+  {__LINE__, 999.998,                  "1000", "%.5g"},
+  {__LINE__, 999.998,                  "1000.0", "%#.5g"},
+  {__LINE__, 999.9998,                 "1000", "%g"},
+  {__LINE__, 999.9998,                 "1000.00", "%#g"},
+  {__LINE__, 912.98,                   "913", "%.4g"},
+  {__LINE__, 50.999999,                        "51", "%.5g"},
+
+  {__LINE__, 0.0,                      "0000.00000", "%010.5f"},
+  {__LINE__, 0.0,                      " 000.00000", "% 010.5f"},
+  {__LINE__, -0.0,                     "-000.00000", "% 010.5f"},
+
+  {__LINE__, NAN,                      "nan", "%f"},
+  {__LINE__, NAN,                      "+nan", "%+f"},
+  {__LINE__, NAN,                      "       nan", "%010.2f"},
+  {__LINE__, NAN,                      "      +nan", "%+010.2f"},
+  {__LINE__, -NAN,                     "-nan", "%f"},
+  {__LINE__, -NAN,                     "-nan", "%+f"},
+  {__LINE__, -NAN,                     "      -nan", "%010.2f"},
+  {__LINE__, -NAN,                     "      -nan", "%+010.2f"},
+  {__LINE__, NAN,                      "NAN", "%F"},
+  {__LINE__, INFINITY,                 "inf", "%f"},
+  {__LINE__, INFINITY,                 "+inf", "%+f"},
+  {__LINE__, INFINITY,                 "       inf", "%010.2f"},
+  {__LINE__, INFINITY,                 "      +inf", "%+010.2f"},
+  {__LINE__, -INFINITY,                        "-inf", "%f"},
+  {__LINE__, -INFINITY,                        "-inf", "%+f"},
+  {__LINE__, -INFINITY,                        "      -inf", "%010.2f"},
+  {__LINE__, -INFINITY,                        "      -inf", "%+010.2f"},
+  {__LINE__, INFINITY,                 "INF", "%F"},
 
   {0 }
 
@@ -4023,13 +4077,8 @@ sprint_double_type sprint_doubles[] =
 
 int required_precision = 13;
 
-#if defined(__STDC__) || defined(__cplusplus)
 static int
-matches (register char *result, register const char *desired)
-#else
-int matches(result, desired)
-     register char *result; register const char *desired;
-#endif
+matches (char *result, const char *desired)
 {
     int digits_seen = 0;
     for (;; result++, desired++) {
@@ -4069,7 +4118,7 @@ int main(int argc, char *argv[])
 
       sprintf (buffer, "%.999g", dptr->value);
       sscanf (buffer, "%lg", &d);
-      if (dptr->value != d)
+      if (dptr->value != d && !isnan(d))
        {
          errcount++;
          printf ("Error in line %d.  String is \"%s\", value is %g.\n",
@@ -4080,7 +4129,7 @@ int main(int argc, char *argv[])
 
   /* And one special test.  */
   {
-    const char ref[] = "1.7763568394002504646778106689453125e-15";
+    static const char ref[] = "1.7763568394002504646778106689453125e-15";
     int i;
     d = 1.0;
     for (i = 1; i < 50; ++i)