* [PATCH] stdio-common: Add a few double formatting tests [BZ #27245]
@ 2021-01-27 4:45 Mike Hommey
2021-01-29 14:50 ` Adhemerval Zanella
0 siblings, 1 reply; 3+ messages in thread
From: Mike Hommey @ 2021-01-27 4:45 UTC (permalink / raw)
To: libc-alpha; +Cc: Mike Hommey
This adds tests for corner cases that I've found while implementing a
printf based on https://github.com/google/double-conversion/ but weren't
covered by the printf formatting tests in glibc (which I was using as a
source of test cases).
Copyright-paperwork-exempt: Yes
---
stdio-common/tfformat.c | 30 +++++++++++++++++++++++++++++-
1 file changed, 29 insertions(+), 1 deletion(-)
diff --git a/stdio-common/tfformat.c b/stdio-common/tfformat.c
index 5cb366dd48..4eb47f0c2b 100644
--- a/stdio-common/tfformat.c
+++ b/stdio-common/tfformat.c
@@ -1,3 +1,4 @@
+#include <math.h>
#include <stdio.h>
/* Tests taken from Cygnus C library. */
@@ -4009,6 +4010,10 @@ 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"},
@@ -4039,6 +4044,29 @@ sprint_double_type sprint_doubles[] =
{__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 }
};
@@ -4090,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",
--
2.30.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] stdio-common: Add a few double formatting tests [BZ #27245]
2021-01-27 4:45 [PATCH] stdio-common: Add a few double formatting tests [BZ #27245] Mike Hommey
@ 2021-01-29 14:50 ` Adhemerval Zanella
2021-02-04 8:03 ` Mike Hommey
0 siblings, 1 reply; 3+ messages in thread
From: Adhemerval Zanella @ 2021-01-29 14:50 UTC (permalink / raw)
To: Mike Hommey, libc-alpha
On 27/01/2021 01:45, Mike Hommey wrote:
> This adds tests for corner cases that I've found while implementing a
> printf based on https://github.com/google/double-conversion/ but weren't
> covered by the printf formatting tests in glibc (which I was using as a
> source of test cases).
>
> Copyright-paperwork-exempt: Yes
LGTM for 2.34.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
> ---
> stdio-common/tfformat.c | 30 +++++++++++++++++++++++++++++-
> 1 file changed, 29 insertions(+), 1 deletion(-)
>
> diff --git a/stdio-common/tfformat.c b/stdio-common/tfformat.c
> index 5cb366dd48..4eb47f0c2b 100644
> --- a/stdio-common/tfformat.c
> +++ b/stdio-common/tfformat.c
> @@ -1,3 +1,4 @@
> +#include <math.h>
> #include <stdio.h>
>
> /* Tests taken from Cygnus C library. */
> @@ -4009,6 +4010,10 @@ 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"},
> @@ -4039,6 +4044,29 @@ sprint_double_type sprint_doubles[] =
> {__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 }
>
> };
> @@ -4090,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",
>
Maybe bail out early in the loop, like:
if (isnan (d))
continue;
sprintf (...)
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] stdio-common: Add a few double formatting tests [BZ #27245]
2021-01-29 14:50 ` Adhemerval Zanella
@ 2021-02-04 8:03 ` Mike Hommey
0 siblings, 0 replies; 3+ messages in thread
From: Mike Hommey @ 2021-02-04 8:03 UTC (permalink / raw)
To: Adhemerval Zanella; +Cc: libc-alpha
On Fri, Jan 29, 2021 at 11:50:30AM -0300, Adhemerval Zanella wrote:
>
>
> On 27/01/2021 01:45, Mike Hommey wrote:
> > This adds tests for corner cases that I've found while implementing a
> > printf based on https://github.com/google/double-conversion/ but weren't
> > covered by the printf formatting tests in glibc (which I was using as a
> > source of test cases).
> >
> > Copyright-paperwork-exempt: Yes
>
> LGTM for 2.34.
>
> Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
>
> (...)
>
> Maybe bail out early in the loop, like:
>
> if (isnan (d))
> continue;
>
> sprintf (...)
That would skip the testcount++.
Would you commit this for me? (I'm not a committer)
Thank you
Mike
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-02-04 8:03 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-27 4:45 [PATCH] stdio-common: Add a few double formatting tests [BZ #27245] Mike Hommey
2021-01-29 14:50 ` Adhemerval Zanella
2021-02-04 8:03 ` Mike Hommey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).