From: Takashi Yano <takashi.yano@nifty.ne.jp>
To: cygwin@cygwin.com
Subject: Re: possible snprintf() regression in 3.3.2
Date: Wed, 24 Nov 2021 17:52:04 +0900 [thread overview]
Message-ID: <20211124175204.ff0751fd1536dde626826dd5@nifty.ne.jp> (raw)
In-Reply-To: <20211124124055.a90e254858b66d42aca6ecef@nifty.ne.jp>
On Wed, 24 Nov 2021 12:40:55 +0900
Takashi Yano wrote:
> On Tue, 23 Nov 2021 10:48:21 +0100
> Corinna Vinschen wrote:
> > On Nov 23 17:34, Takashi Yano via Cygwin wrote:
> > > However, in reality, for example in the case:
> > > snprintf(buf, sizeof(buf), "%.3f", 1234567890123456.789);
> > > 'ndigits' is only 3 even though total digits will be 20.
> > >
> > > So, Tony thinks current code does not correct.
> > >
> > > However, I think something is wrong with interpretation
> > > of 'ndigits' in dltoa.c.
> > >
> > > printf("%.3f\n", sqrt(2)*1e70);
> > > printf("%.50f\n", sqrt(2)*1e70);
> > >
> > > outputs
> > >
> > > 14142135623730951759073108307330633613786387000000000000000000000000000.000
> > > 14142135623730951759073108307330633613786386978891021459448717416650727.13402790000888758223149296720949629080194006476078
> > >
> > > Is this as intended?
> >
> > On Linux I see
> >
> > 14142135623730951759073108307330633613786387161811679011529922516615168.000
> > 14142135623730951759073108307330633613786387161811679011529922516615168.00000000000000000000000000000000000000000000000000
> >
> > The newlib output for .3f probably suffers from the fact that ldtoa
> > chooses the small buffer, which restricts the number of digits to 43 or
> > 44. But keep in mind that ldtoa *always* restricted the output to 42,
> > so you never got a more precise output anyway. Every digit beyond digit
> > 42 is only printed due to the bigger buffer sizes.
> >
> > So, what newlib and, in extension, Cygwin really needs at this point are
> > patches to the existing ldtoa or a change to gdtoa or equivalent.
> >
> > https://cygwin.com/acronyms/#SHTDI
> > https://cygwin.com/acronyms/#PTC
>
> The attached patch is the one which I think correct so far.
>
> With this patch:
>
> 14142135623730951759073108307330633613786386978891021459448717416650727.134
> 14142135623730951759073108307330633613786386978891021459448717416650727.13402790000888758223149296720949629080194006476078
>
> Isn't this better than current behaviour?
The printed value is still something wrong...
sqrt(2)*1e70 should be an integer value.
sqrt(2)*1e62: OK
141421356237309519594917508377920125928940956418610020629872640.000000
sqrt(2)*1e63: NG
1414213562373095241621101250369917453154560547438491094548266395.615752
I will look into this problem.
--
Takashi Yano <takashi.yano@nifty.ne.jp>
next prev parent reply other threads:[~2021-11-24 8:52 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-17 0:37 Tony Cook
2021-11-17 9:21 ` Takashi Yano
2021-11-17 12:27 ` Corinna Vinschen
2021-11-18 0:06 ` Tony Cook
2021-11-18 11:35 ` Takashi Yano
2021-11-18 13:19 ` Corinna Vinschen
2021-11-18 14:11 ` Noel Grandin
2021-11-18 14:27 ` Corinna Vinschen
2021-11-18 21:08 ` Sam Edge
2021-11-21 0:16 ` Tony Cook
2021-11-22 10:34 ` Corinna Vinschen
2021-11-22 13:04 ` Corinna Vinschen
2021-11-22 23:23 ` Tony Cook
2021-11-23 8:34 ` Takashi Yano
2021-11-23 9:48 ` Corinna Vinschen
2021-11-24 3:40 ` Takashi Yano
2021-11-24 8:48 ` Corinna Vinschen
2021-11-24 8:52 ` Takashi Yano [this message]
2021-11-24 9:14 ` Takashi Yano
2021-11-24 9:28 ` Corinna Vinschen
2021-11-24 12:29 ` Lemke, Michael SF/HZA-ZI2E
2021-11-25 12:02 ` Takashi Yano
2021-11-25 12:45 ` Corinna Vinschen
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=20211124175204.ff0751fd1536dde626826dd5@nifty.ne.jp \
--to=takashi.yano@nifty.ne.jp \
--cc=cygwin@cygwin.com \
/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).