From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/4824 Path: news.gmane.org!not-for-mail From: Morten Welinder Newsgroups: gmane.linux.lib.musl.general Subject: Re: printf issues Date: Mon, 7 Apr 2014 10:13:26 -0400 Message-ID: References: <20140404141515.GD3034@port70.net> <20140404150705.GN26358@brightrain.aerifal.cx> <20140404185413.GH3034@port70.net> <20140404210837.GS26358@brightrain.aerifal.cx> <20140407072930.GB26358@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: ger.gmane.org 1396880028 21046 80.91.229.3 (7 Apr 2014 14:13:48 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 7 Apr 2014 14:13:48 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-4828-gllmg-musl=m.gmane.org@lists.openwall.com Mon Apr 07 16:13:41 2014 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1WXAIt-0004P0-DJ for gllmg-musl@plane.gmane.org; Mon, 07 Apr 2014 16:13:39 +0200 Original-Received: (qmail 13693 invoked by uid 550); 7 Apr 2014 14:13:38 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 13684 invoked from network); 7 Apr 2014 14:13:37 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=GuostLI/i//anSfCcd8EEkEjJeGvmbdNPTmUtEXxZeU=; b=v49DMRDwOOIz2j3+7MqLxWAnLtZFiZnpT1EoEYTOT2zffo/Rz81gKaEcXjz0f8cVJx 8BFWnfYVJ6Es7amtrGtfZmKTxVuUC2PGxF1nV5IKtU1n4JLPo5/Mw6G1lescJkVLkP89 voMM9lVxJG77orT0L9BXza0NN9DorJgZC77ieCnC+Drmj78Z2iEgVgXCvRM4YJsqGqUM YRhznvmWKg330OZGrF3TlfPUSSx+L5vEcvM3BT3QULWBT6t2tfZjKMvr2oHv2JD2h/GQ hUJvgI1T4JifKPegY9eqKUZhgsqlPPg6Llq6HCAk3TPk7Ddhhf9NVG9zKZLSKeZglOoh GlcQ== X-Received: by 10.180.14.40 with SMTP id m8mr17357725wic.31.1396880006200; Mon, 07 Apr 2014 07:13:26 -0700 (PDT) In-Reply-To: Xref: news.gmane.org gmane.linux.lib.musl.general:4824 Archived-At: The frequency of this problem is something like 1 in 5e6. Observations: * I only seem to be able to trigger it for %g even though all my samples print in "e" form. * The numbers are all roughly the same size: 1e15 * The numbers are all integers ending in 05. (Except two cases where the 05 is followed by zeros.) * The precision is always just below the value that would have make an exact representation. Morten Test #1165601 at precision 15: -4.15655192121011e+15 -4.1565519212101e+15 -0xe.c45ca8c112f9p+48 -4156551921210105 Test #7022240 at precision 15: -8.18656081955811e+15 -8.1865608195581e+15 -0xe.8ad11cca7b6c8p+49 -8186560819558105 Test #7718112 at precision 15: -3.57044516323631e+15 -3.5704451632363e+15 -0xc.af4d0ba50bd1p+48 -3570445163236305 Test #7772566 at precision 15: 2.50163300941741e+15 2.5016330094174e+15 0x8.e338d2e27cbdp+48 2501633009417405 Test #8135560 at precision 15: -8.75451694516931e+15 -8.7545169451693e+15 -0xf.8d17e85935cc8p+49 -8754516945169305 Test #11526318 at precision 15: 7.64406482711661e+15 7.6440648271166e+15 0xd.941e4454861e8p+49 7644064827116605 Test #13957100 at precision 14: -9.7205430380441e+14 -9.720543038044e+14 -0xd.d0501dec2fd4p+46 -972054303804405 Test #20008327 at precision 15: 3.37380293784171e+15 3.3738029378417e+15 0xb.fc74b5a6f829p+48 3373802937841705 Test #23073645 at precision 14: -5.1833238325691e+15 -5.183323832569e+15 -0x9.351a4fe5e66dp+49 -5183323832569050 Test #25660410 at precision 15: 3.96328205296061e+15 3.9632820529606e+15 0xe.149582e9515dp+48 3963282052960605 Test #29106716 at precision 13: 8.042000473751e+15 8.04200047375e+15 0xe.491412c2bdf2p+49 8042000473750500 Test #35240073 at precision 15: 1.96456678790721e+15 1.9645667879072e+15 0xd.f586b30fbd0ap+47 1964566787907205 Test #35298996 at precision 15: 6.67034256219981e+15 6.6703425621998e+15 0xb.d95213799c7e8p+49 6670342562199805 Test #36728927 at precision 13: -2.920984132831e+13 -2.92098413283e+13 -0xd.48791bb0588p+41 -29209841328305 Test #40382272 at precision 15: 8.82887106290361e+15 8.8288710629036e+15 0xf.aee7ddbc6d9a8p+49 8828871062903605 Test #44394631 at precision 14: -2.4546341550581e+14 -2.454634155058e+14 -0xd.f3f67afc38dp+44 -245463415505805 Test #56164412 at precision 15: -5.26534878693031e+15 -5.2653487869303e+15 -0x9.5a67460821408p+49 -5265348786930305 Test #58309890 at precision 15: -3.54820922268461e+15 -3.5482092226846e+15 -0xc.9b13d64e8fbdp+48 -3548209222684605 Test #64933676 at precision 15: 5.61427609297841e+15 5.6142760929784e+15 0x9.f913c218b2728p+49 5614276092978405 Test #70560963 at precision 15: -2.75797952567011e+15 -2.7579795256701e+15 -0x9.cc5e25ece4d9p+48 -2757979525670105 Test #80659572 at precision 15: 1.99612924552141e+15 1.9961292455214e+15 0xe.2ef01d35cbfap+47 1996129245521405 On Mon, Apr 7, 2014 at 9:40 AM, Morten Welinder wrote: > I am seeing another case of printing the wrong result. (This is with > the pre-fix code, but I don't think that matters.) > > For 0xc.301316272b908p+49L (aka 6861116509411105.0L) with format > "%.15Lg" I get > > musl: 6.86111650941111e+15 > glibc: 6.8611165094111e+15 > > Musl has rounded to odd here for a midpoint case. > > Morten > > > > > > > > On Mon, Apr 7, 2014 at 3:29 AM, Rich Felker wrote: >> On Fri, Apr 04, 2014 at 08:01:00PM -0400, Morten Welinder wrote: >>> I *think* the right fix is to add the following "if' statement into >>> the rounding loop: >>> >>> while (*d > 999999999) { >>> *d--=0; >>> if (d < a) *--a = 0; >>> (*d)++; >>> } >>> >>> This also ought to make the d>> more tests would be better. >> >> After re-studying the code, I think this is the correct fix, and I've >> committed the fix to git. I also fixed the bug where %g failed to trim >> trailing zeros. >> >> Rich