From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.17.10]) by sourceware.org (Postfix) with ESMTPS id D73163858423 for ; Wed, 24 Nov 2021 08:48:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D73163858423 Received: from calimero.vinschen.de ([24.134.7.25]) by mrelayeu.kundenserver.de (mreue109 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MMXYH-1n6Vae0Mf1-00JXCj for ; Wed, 24 Nov 2021 09:48:27 +0100 Received: by calimero.vinschen.de (Postfix, from userid 500) id 6C783A80D65; Wed, 24 Nov 2021 09:48:26 +0100 (CET) Date: Wed, 24 Nov 2021 09:48:26 +0100 From: Corinna Vinschen To: cygwin@cygwin.com Subject: Re: possible snprintf() regression in 3.3.2 Message-ID: Reply-To: cygwin@cygwin.com Mail-Followup-To: cygwin@cygwin.com References: <7545bb24-43de-cd7d-0764-55c85f1af957@gmx.com> <20211121001613.GH10332@venus.tony.develop-help.com> <20211122232302.GI10332@venus.tony.develop-help.com> <20211123173409.0db4d5ccd94501ce1b8f69ea@nifty.ne.jp> <20211124124055.a90e254858b66d42aca6ecef@nifty.ne.jp> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20211124124055.a90e254858b66d42aca6ecef@nifty.ne.jp> X-Provags-ID: V03:K1:AnOrk1LrvqZ+eGPNBe/sy0wFLcMisOCBvHyBI9V0Sexp6CXQWxP t3ob2HTbhqWsq9tjglSc1pwMGFD4GWUVeT8G3K/UhyTukrotODfZyZ49kB6hrGHV57sK7oL NKDvw87dp7TGcb/802zTS6tV+ozG0+dAoFq2CnrATXGfw1VQ5lERuIHDnzFBrxwBnc0Aj2m F+ATFHUOMLXaoi55w1xKA== X-UI-Out-Filterresults: notjunk:1;V03:K0:aAhCaVu5RqM=:U4weaacwcmkcH+zqMoIpAX ExNuWHcCnC7/yTqSKmEKwsPJQ33Jv+5c4WKOZo5CGYA9RKaElux5xBXmzvIAQPdBmvprw/Njx hB01wo87FpGesPso9P93AIvNppZ7tW0vGVMpLqmCMsb/0U5iLY8oqRlMZR2LXndv/PoYqzE4Q xQzIM9qnyN2BEzMgNOTG4Jkb00as42jpb6b9twTPX5TKz6jfCR9Ii00+UISAehsMfez/UbE8J MXVq2RumuCI5JqUvK8Y6azHhAeBTmE592VHswN9Tr6IrgovRmvv9W9OofFsI8HAoO1daJRs6j arGsDErh3cEVjaaZN4YbaFRx4Zek+P90/i89Tq+3cNIBacVmiSMwQ47Om/ZX6hlevS72Zc26m VPGOGd1pvl/rj08VpwSpTAaf6hZcVtzy8f4M1MV4QBx5WZR8MZtlbHNx855CSrFPTrkDax4nq 6ww8QN2CPsVSPrhz1zuisrjcjtaREyGBOLpwxR2oRYLNFXRP+Hw7Z3dy9xWTdqzIYJvphDKwq YiNqj5kYK3qoMhhT3riFpJA/Ebnak/JxDfrGnlGl1kKEBFgD3Ib2I30uNxHMWqBoMlyZaP923 qEL930xO9m25Td3KaEkiAU/Yh3r/klU2byp3cAQhh4fH6H3sGrENYRWs5k/W43YMexHFfebBk C+lrh+O+3QN5TywFtFiwhv+jjHejcpx+sjpBY1+9i6meOOWfmsN9ePJPE9t088xOY0t3PdRTl QWD7a247Cw6K7dZ8 X-Spam-Status: No, score=-99.0 required=5.0 tests=BAYES_00, GOOD_FROM_CORINNA_CYGWIN, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LOTSOFHASH, KAM_NUMSUBJECT, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: cygwin@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: General Cygwin discussions and problem reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Nov 2021 08:48:32 -0000 On Nov 24 12:40, Takashi Yano via Cygwin 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? LGTM, thanks! Can you send this as patch to the newlib ML, please? Thanks, Corinna