From: Morten Welinder <mwelinder@gmail.com>
To: musl@lists.openwall.com
Subject: Re: printf issues
Date: Mon, 7 Apr 2014 10:13:26 -0400 [thread overview]
Message-ID: <CANv4PNnpopdNb6b_-uqahy=zEVes0yMMkEUYJFdJk0yu1JASmw@mail.gmail.com> (raw)
In-Reply-To: <CANv4PN=MvbcrCv28Z=+3BumvtivELh_teUp=O6Ogfu7Aob2CTQ@mail.gmail.com>
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@gmail.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@aerifal.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
next prev parent reply other threads:[~2014-04-07 14:13 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-04 13:32 Morten Welinder
2014-04-04 14:12 ` Rich Felker
2014-04-04 14:15 ` Szabolcs Nagy
2014-04-04 14:35 ` Morten Welinder
2014-04-04 14:56 ` Szabolcs Nagy
2014-04-04 15:07 ` Rich Felker
2014-04-04 17:42 ` Morten Welinder
2014-04-04 18:54 ` Szabolcs Nagy
2014-04-04 20:01 ` Morten Welinder
2014-04-04 20:22 ` Morten Welinder
2014-04-04 21:08 ` Rich Felker
2014-04-04 22:50 ` Morten Welinder
2014-04-05 0:01 ` Morten Welinder
2014-04-05 1:41 ` Rich Felker
2014-04-07 7:29 ` Rich Felker
2014-04-07 13:40 ` Morten Welinder
2014-04-07 14:13 ` Morten Welinder [this message]
2014-04-07 15:36 ` Szabolcs Nagy
2014-04-07 18:04 ` Rich Felker
2014-04-04 20:54 ` Szabolcs Nagy
2014-04-04 21:02 ` Rich Felker
2014-04-05 2:08 ` Morten Welinder
2014-04-05 2:50 ` Rich Felker
2014-04-06 23:07 ` Szabolcs Nagy
2014-04-04 21:00 ` Rich Felker
2014-04-04 21:10 ` Szabolcs Nagy
2014-04-04 20:58 ` Rich Felker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CANv4PNnpopdNb6b_-uqahy=zEVes0yMMkEUYJFdJk0yu1JASmw@mail.gmail.com' \
--to=mwelinder@gmail.com \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).