mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Szabolcs Nagy <nsz@port70.net>
To: musl@lists.openwall.com
Subject: Re: printf issues
Date: Mon, 7 Apr 2014 17:36:11 +0200	[thread overview]
Message-ID: <20140407153611.GM3034@port70.net> (raw)
In-Reply-To: <CANv4PNnpopdNb6b_-uqahy=zEVes0yMMkEUYJFdJk0yu1JASmw@mail.gmail.com>

* Morten Welinder <mwelinder@gmail.com> [2014-04-07 10:13:26 -0400]:
> 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.

printf("%.12g\n", 1000000000005.0);
printf("%.11g\n", 500000000045.0);
printf("%.11g\n", 275000000025.0);

prints

1.00000000001e+12
5.0000000005e+11
2.7500000003e+11

in fmt_fp
	if (x || d+1!=z) {
		long double round = CONCAT(0x1p,LDBL_MANT_DIG);
		long double small;
		if (*d/i & 1) round += 2;
		if (x<i/2) small=0x0.8p0;
		else if (x==i/2 && d+1==z) small=0x1.0p0;
		else small=0x1.8p0;
		...

here
	i == 10
	x == *d%i == 5 == i/2
but the half-way case does not trigger because z-d == 2 instead of 1
and z[-1] == 0 which should not happen here


  reply	other threads:[~2014-04-07 15:36 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
2014-04-07 15:36                           ` Szabolcs Nagy [this message]
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=20140407153611.GM3034@port70.net \
    --to=nsz@port70.net \
    --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).