Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CANv4PNnpopdNb6b_-uqahy=zEVes0yMMkEUYJFdJk0yu1JASmw@mail.gmail.com>
Date: Mon, 7 Apr 2014 10:13:26 -0400
From: Morten Welinder <mwelinder@...il.com>
To: musl@...ts.openwall.com
Subject: Re: printf issues

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 <mwelinder@...il.com> 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 <dalias@...ifal.cx> 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<a test afterwards unnecessary.  But
>>> 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

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.