X-Recipient: archive-cygwin AT delorie DOT com DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0CE3D3858000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com; s=default; t=1637744014; bh=AA9KUtug8AclBdmAvvEW9TCYsiPAo4PNguTsbyucFgk=; h=Date:To:Subject:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=uZLshDUDD6oOfpkDdLq7Dje2TNgvwuDIxnL0dSv/qcqXcVxCHkKGdyARwq1FTA4H/ jqxAOYV2awBXG3yVZPqL8SaFmtEv8/vlGOauUfZVJdEYl/akLcFuxxM68umnVTEDku d9mQLWmg/TOyCshcEtVaX2ptsZ0B+8P/mWIkAWrA= X-Original-To: cygwin AT cygwin DOT com Delivered-To: cygwin AT cygwin DOT com DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 812573858018 DKIM-Filter: OpenDKIM Filter v2.10.3 conssluserg-01.nifty.com 1AO8q4HE009627 X-Nifty-SrcIP: [110.4.221.123] Date: Wed, 24 Nov 2021 17:52:04 +0900 To: cygwin AT cygwin DOT com Subject: Re: possible snprintf() regression in 3.3.2 Message-Id: <20211124175204.ff0751fd1536dde626826dd5@nifty.ne.jp> In-Reply-To: <20211124124055.a90e254858b66d42aca6ecef@nifty.ne.jp> References: <20211118203538 DOT a049809d57731fe375801c15 AT nifty DOT ne DOT jp> <7545bb24-43de-cd7d-0764-55c85f1af957 AT gmx DOT com> <20211121001613 DOT GH10332 AT venus DOT tony DOT develop-help DOT com> <20211122232302 DOT GI10332 AT venus DOT tony DOT develop-help DOT com> <20211123173409 DOT 0db4d5ccd94501ce1b8f69ea AT nifty DOT ne DOT jp> <20211124124055 DOT a90e254858b66d42aca6ecef AT nifty DOT ne DOT jp> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32) Mime-Version: 1.0 X-Spam-Status: No, score=-6.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_LOTSOFHASH, KAM_NUMSUBJECT, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, 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 AT cygwin DOT 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: , From: Takashi Yano via Cygwin Reply-To: Takashi Yano Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: cygwin-bounces+archive-cygwin=delorie DOT com AT cygwin DOT com Sender: "Cygwin" 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 -- Problem reports: https://cygwin.com/problems.html FAQ: https://cygwin.com/faq/ Documentation: https://cygwin.com/docs.html Unsubscribe info: https://cygwin.com/ml/#unsubscribe-simple