public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: Mike Hommey <mh@glandium.org>, libc-alpha@sourceware.org
Subject: Re: [PATCH] stdio-common: Add a few double formatting tests [BZ #27245]
Date: Fri, 29 Jan 2021 11:50:30 -0300	[thread overview]
Message-ID: <285fffba-4c9e-e9f0-020b-8ce7f18aa12b@linaro.org> (raw)
In-Reply-To: <20210127044505.6783-1-mh@glandium.org>



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 (...)

  reply	other threads:[~2021-01-29 14:50 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-27  4:45 Mike Hommey
2021-01-29 14:50 ` Adhemerval Zanella [this message]
2021-02-04  8:03   ` Mike Hommey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=285fffba-4c9e-e9f0-020b-8ce7f18aa12b@linaro.org \
    --to=adhemerval.zanella@linaro.org \
    --cc=libc-alpha@sourceware.org \
    --cc=mh@glandium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).