aboutsummaryrefslogtreecommitdiff
path: root/stdio-common/tst-printf.c
diff options
context:
space:
mode:
authorSiddhesh Poyarekar <siddhesh@sourceware.org>2021-02-05 09:52:52 +0530
committerSiddhesh Poyarekar <siddhesh@sourceware.org>2021-02-05 09:52:52 +0530
commit921e6f419867ae0ec15b6b5182f194a8229e7941 (patch)
tree8b5466ea003a6ff2f6f7c0ec50776a4b6ab1b1eb /stdio-common/tst-printf.c
parent339f7fea92fa6a43688e54712aec58dd223904e5 (diff)
downloadglibc-921e6f419867ae0ec15b6b5182f194a8229e7941.zip
glibc-921e6f419867ae0ec15b6b5182f194a8229e7941.tar.gz
glibc-921e6f419867ae0ec15b6b5182f194a8229e7941.tar.bz2
printf: Add smoke tests for long double
The printf tests have no coverage for long double. Duplicate the double tests so that we have some basic coverage. Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Diffstat (limited to 'stdio-common/tst-printf.c')
-rw-r--r--stdio-common/tst-printf.c65
1 files changed, 55 insertions, 10 deletions
diff --git a/stdio-common/tst-printf.c b/stdio-common/tst-printf.c
index 2c4624c..b424133 100644
--- a/stdio-common/tst-printf.c
+++ b/stdio-common/tst-printf.c
@@ -127,21 +127,39 @@ I am ready for my first lesson today.";
printf("e-style < .1:\t\"%e\"\n", 0.001234);
printf("e-style big:\t\"%.60e\"\n", 1e20);
printf ("e-style == .1:\t\"%e\"\n", 0.1);
+ printf("f-style == 0:\t\"%f\"\n", 0.0);
printf("f-style >= 1:\t\"%f\"\n", 12.34);
printf("f-style >= .1:\t\"%f\"\n", 0.1234);
printf("f-style < .1:\t\"%f\"\n", 0.001234);
+ printf("g-style == 0:\t\"%g\"\n", 0.0);
printf("g-style >= 1:\t\"%g\"\n", 12.34);
printf("g-style >= .1:\t\"%g\"\n", 0.1234);
printf("g-style < .1:\t\"%g\"\n", 0.001234);
printf("g-style big:\t\"%.60g\"\n", 1e20);
+ printf("Lf-style == 0:\t\"%Lf\"\n", (long double) 0.0);
+ printf("Lf-style >= 1:\t\"%Lf\"\n", (long double) 12.34);
+ printf("Lf-style >= .1:\t\"%Lf\"\n", (long double) 0.1234);
+ printf("Lf-style < .1:\t\"%Lf\"\n", (long double) 0.001234);
+ printf("Lg-style == 0:\t\"%Lg\"\n", (long double) 0.0);
+ printf("Lg-style >= 1:\t\"%Lg\"\n", (long double) 12.34);
+ printf("Lg-style >= .1:\t\"%Lg\"\n", (long double) 0.1234);
+ printf("Lg-style < .1:\t\"%Lg\"\n", (long double) 0.001234);
+ printf("Lg-style big:\t\"%.60Lg\"\n", (long double) 1e20);
+
printf (" %6.5f\n", .099999999860301614);
printf (" %6.5f\n", .1);
printf ("x%5.4fx\n", .5);
+ printf (" %6.5Lf\n", (long double) .099999999860301614);
+ printf (" %6.5Lf\n", (long double) .1);
+ printf ("x%5.4Lfx\n", (long double) .5);
+
printf ("%#03x\n", 1);
printf ("something really insane: %.10000f\n", 1.0);
+ printf ("something really insane (long double): %.10000Lf\n",
+ (long double) 1.0);
{
double d = FLT_MIN;
@@ -154,16 +172,25 @@ I am ready for my first lesson today.";
printf ("%15.5e\n", 4.9406564584124654e-324);
-#define FORMAT "|%12.4f|%12.4e|%12.4g|\n"
- printf (FORMAT, 0.0, 0.0, 0.0);
- printf (FORMAT, 1.0, 1.0, 1.0);
- printf (FORMAT, -1.0, -1.0, -1.0);
- printf (FORMAT, 100.0, 100.0, 100.0);
- printf (FORMAT, 1000.0, 1000.0, 1000.0);
- printf (FORMAT, 10000.0, 10000.0, 10000.0);
- printf (FORMAT, 12345.0, 12345.0, 12345.0);
- printf (FORMAT, 100000.0, 100000.0, 100000.0);
- printf (FORMAT, 123456.0, 123456.0, 123456.0);
+#define FORMAT "|%12.4f|%12.4e|%12.4g|%12.4Lf|%12.4Lg|\n"
+ printf (FORMAT, 0.0, 0.0, 0.0,
+ (long double) 0.0, (long double) 0.0);
+ printf (FORMAT, 1.0, 1.0, 1.0,
+ (long double) 1.0, (long double) 1.0);
+ printf (FORMAT, -1.0, -1.0, -1.0,
+ (long double) -1.0, (long double) -1.0);
+ printf (FORMAT, 100.0, 100.0, 100.0,
+ (long double) 100.0, (long double) 100.0);
+ printf (FORMAT, 1000.0, 1000.0, 1000.0,
+ (long double) 1000.0, (long double) 1000.0);
+ printf (FORMAT, 10000.0, 10000.0, 10000.0,
+ (long double) 10000.0, (long double) 10000.0);
+ printf (FORMAT, 12345.0, 12345.0, 12345.0,
+ (long double) 12345.0, (long double) 12345.0);
+ printf (FORMAT, 100000.0, 100000.0, 100000.0,
+ (long double) 100000.0, (long double) 100000.0);
+ printf (FORMAT, 123456.0, 123456.0, 123456.0,
+ (long double) 123456.0, (long double) 123456.0);
#undef FORMAT
{
@@ -271,6 +298,9 @@ rfg1 (void)
sprintf (buf, "%5.f", 33.3);
if (strcmp (buf, " 33") != 0)
printf ("got: '%s', expected: '%s'\n", buf, " 33");
+ sprintf (buf, "%5.Lf", (long double) 33.3);
+ if (strcmp (buf, " 33") != 0)
+ printf ("got: '%s', expected: '%s'\n", buf, " 33");
sprintf (buf, "%8.e", 33.3e7);
if (strcmp (buf, " 3e+08") != 0)
printf ("got: '%s', expected: '%s'\n", buf, " 3e+08");
@@ -280,6 +310,9 @@ rfg1 (void)
sprintf (buf, "%.g", 33.3);
if (strcmp (buf, "3e+01") != 0)
printf ("got: '%s', expected: '%s'\n", buf, "3e+01");
+ sprintf (buf, "%.Lg", (long double) 33.3);
+ if (strcmp (buf, "3e+01") != 0)
+ printf ("got: '%s', expected: '%s'\n", buf, "3e+01");
sprintf (buf, "%.G", 33.3);
if (strcmp (buf, "3E+01") != 0)
printf ("got: '%s', expected: '%s'\n", buf, "3E+01");
@@ -303,6 +336,18 @@ rfg2 (void)
sprintf (buf, "%7.*G", prec, 3.33);
if (strcmp (buf, " 3") != 0)
printf ("got: '%s', expected: '%s'\n", buf, " 3");
+ prec = 0;
+ sprintf (buf, "%.*Lg", prec, (long double) 3.3);
+ if (strcmp (buf, "3") != 0)
+ printf ("got: '%s', expected: '%s'\n", buf, "3");
+ prec = 0;
+ sprintf (buf, "%.*LG", prec, (long double) 3.3);
+ if (strcmp (buf, "3") != 0)
+ printf ("got: '%s', expected: '%s'\n", buf, "3");
+ prec = 0;
+ sprintf (buf, "%7.*LG", prec, (long double) 3.33);
+ if (strcmp (buf, " 3") != 0)
+ printf ("got: '%s', expected: '%s'\n", buf, " 3");
prec = 3;
sprintf (buf, "%04.*o", prec, 33);
if (strcmp (buf, " 041") != 0)