delorie.com/archives/browse.cgi | search |
X-Recipient: | archive-cygwin AT delorie DOT com |
DKIM-Filter: | OpenDKIM Filter v2.11.0 sourceware.org 87D613858D28 |
DKIM-Signature: | v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com; |
s=default; t=1637725339; | |
bh=2KTJsv5N/Y0HN955ARzaxlqpE2WrEWf3q6TO2w3ALFI=; | |
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=eLhMhkZysAzClzH54XB37BXbLQtaS0qTdNZnTEmAsAtc6Bh+wU8kdddUGvCC7PTVJ | |
FnMp8cEEYRlD1Ts/y3iupfHItwOM4C5Y5xz/WigUCbZfy31ipsu1pLrdYZr0jY9dsm | |
L2/ivQqrL0eFQj6PDMBDSrQ+ObN3SrMAG6YyQSdE= | |
X-Original-To: | cygwin AT cygwin DOT com |
Delivered-To: | cygwin AT cygwin DOT com |
DMARC-Filter: | OpenDMARC Filter v1.4.1 sourceware.org 8D1BE3858D28 |
DKIM-Filter: | OpenDKIM Filter v2.10.3 conssluserg-06.nifty.com 1AO3ejln023550 |
X-Nifty-SrcIP: | [110.4.221.123] |
Date: | Wed, 24 Nov 2021 12:40:55 +0900 |
To: | cygwin AT cygwin DOT com |
Subject: | Re: possible snprintf() regression in 3.3.2 |
Message-Id: | <20211124124055.a90e254858b66d42aca6ecef@nifty.ne.jp> |
In-Reply-To: | <YZy45cStTTgLp0gO@calimero.vinschen.de> |
References: | <20211118203538 DOT a049809d57731fe375801c15 AT nifty DOT ne DOT jp> |
<YZZSzPhbqF6cQAiu AT calimero DOT vinschen DOT de> | |
<fa647f83-c5ed-6dea-fcba-c8b799abe12f AT gmail DOT com> | |
<YZZi3rI5msk6ksAV AT calimero DOT vinschen DOT de> | |
<7545bb24-43de-cd7d-0764-55c85f1af957 AT gmx DOT com> | |
<20211121001613 DOT GH10332 AT venus DOT tony DOT develop-help DOT com> | |
<YZtyJDXdrMzVR2lJ AT calimero DOT vinschen DOT de> | |
<YZuVRjYoG40cEGDV AT calimero DOT vinschen DOT de> | |
<20211122232302 DOT GI10332 AT venus DOT tony DOT develop-help DOT com> | |
<20211123173409 DOT 0db4d5ccd94501ce1b8f69ea AT nifty DOT ne DOT jp> | |
<YZy45cStTTgLp0gO AT calimero DOT vinschen DOT de> | |
X-Mailer: | Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32) |
Mime-Version: | 1.0 |
X-Spam-Status: | No, score=-5.7 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, 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 |
List-Id: | General Cygwin discussions and problem reports <cygwin.cygwin.com> |
List-Unsubscribe: | <https://cygwin.com/mailman/options/cygwin>, |
<mailto:cygwin-request AT cygwin DOT com?subject=unsubscribe> | |
List-Archive: | <https://cygwin.com/pipermail/cygwin/> |
List-Post: | <mailto:cygwin AT cygwin DOT com> |
List-Help: | <mailto:cygwin-request AT cygwin DOT com?subject=help> |
List-Subscribe: | <https://cygwin.com/mailman/listinfo/cygwin>, |
<mailto:cygwin-request AT cygwin DOT com?subject=subscribe> | |
From: | Takashi Yano via Cygwin <cygwin AT cygwin DOT com> |
Reply-To: | Takashi Yano <takashi DOT yano AT nifty DOT ne DOT jp> |
Errors-To: | cygwin-bounces+archive-cygwin=delorie DOT com AT cygwin DOT com |
Sender: | "Cygwin" <cygwin-bounces+archive-cygwin=delorie DOT com AT cygwin DOT com> |
This is a multi-part message in MIME format. --Multipart=_Wed__24_Nov_2021_12_40_55_+0900_3DcUNHT0_HKTxpOV Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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? -- Takashi Yano <takashi DOT yano AT nifty DOT ne DOT jp> --Multipart=_Wed__24_Nov_2021_12_40_55_+0900_3DcUNHT0_HKTxpOV Content-Type: application/octet-stream; name="ldtoa.patch" Content-Disposition: attachment; filename="ldtoa.patch" Content-Transfer-Encoding: base64 ZGlmZiAtLWdpdCBhL25ld2xpYi9saWJjL3N0ZGxpYi9sZHRvYS5jIGIvbmV3bGliL2xpYmMvc3Rk bGliL2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l0cy4gKi8KKyAgaW50IG5kZWM7CisgIGlmIChtb2RlID09IDMpIC8qICVm ICovCisgICAgeworICAgICAgaW50IGV4cG9uID0gKGVbTkUgLSAxXSAmIDB4N2ZmZikgLSAoRVhP TkUgLSAxKTsgLyogZXhwb25lbnQgcGFydCAqLworICAgICAgLyogbG9nMigxMCkgYXBwcm94aW1h dGVseSA0ODUvMTQ2ICovCisgICAgICBuZGVjID0gZXhwb24gKiAxNDYgLyA0ODUgKyBuZGlnaXRz OworICAgIH0KKyAgZWxzZSAvKiAlZy8lZSAqLworICAgIG5kZWMgPSBuZGlnaXRzOworICBpZiAo bmRlYyA8IDApCisgICAgbmRlYyA9IDA7CisgIGlmIChuZGVjID4gTkRFQykKKyAgICBuZGVjID0g TkRFQzsKIAogICAvKiBBbGxvY2F0ZSBidWZmZXIgaWYgbW9yZSB0aGFuIE5ERUNfU01MIGRpZ2l0 cyBhcmUgcmVxdWVzdGVkLiAqLwotICBpZiAobmRpZ2l0cyA+IE5ERUNfU01MKQorICBpZiAobmRl YyA+IE5ERUNfU01MKQogICAgIHsKLSAgICAgIG91dGJ1ZiA9IChjaGFyICopIF9tYWxsb2NfciAo cHRyLCBOREVDICsgTUFYX0VYUF9ESUdJVFMgKyAxMCk7CisgICAgICBvdXRidWYgPSAoY2hhciAq KSBfbWFsbG9jX3IgKHB0ciwgbmRlYyArIE1BWF9FWFBfRElHSVRTICsgMTApOwogICAgICAgaWYg KCFvdXRidWYpCiAJewotCSAgbmRpZ2l0cyA9IE5ERUNfU01MOworCSAgbmRlYyA9IE5ERUNfU01M OwogCSAgb3V0YnVmID0gb3V0YnVmX3NtbDsKIAl9CiAgICAgfQogCi0gIGV0b2FzYyAoZSwgb3V0 YnVmLCBuZGlnaXRzLCBtb2RlLCBsZHApOworICBldG9hc2MgKGUsIG91dGJ1ZiwgbmRlYywgbmRp Z2l0cywgbW9kZSwgbGRwKTsKICAgcyA9IG91dGJ1ZjsKICAgaWYgKGVpc2luZiAoZSkgfHw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QEAgLTMyMDUsOCArMzIxNCw4IEBAIGlzb25lOgogZWxz ZSBpZiggbmRpZ3MgPCAwICkKICAgICAgICAgbmRpZ3MgPSAwOwogKi8KLSAgaWYgKG5kaWdzID4g bXlfTkRFQykKLSAgICBuZGlncyA9IG15X05ERUM7CisgIGlmIChuZGlncyA+IG5kZWMpCisgICAg bmRpZ3MgPSBuZGVjOwogICBpZiAoZGlnaXQgPT0gMTApCiAgICAgewogICAgICAgKnMrKyA9ICcx JzsK --Multipart=_Wed__24_Nov_2021_12_40_55_+0900_3DcUNHT0_HKTxpOV Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline -- 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 --Multipart=_Wed__24_Nov_2021_12_40_55_+0900_3DcUNHT0_HKTxpOV--
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |