From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/10647 Path: news.gmane.org!.POSTED!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH] fix float formatting of some exact halfway cases Date: Thu, 20 Oct 2016 01:55:50 -0400 Message-ID: <20161020055550.GP19318@brightrain.aerifal.cx> References: <20161011224959.GO28065@port70.net> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1476942973 25938 195.159.176.226 (20 Oct 2016 05:56:13 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 20 Oct 2016 05:56:13 +0000 (UTC) User-Agent: Mutt/1.5.21 (2010-09-15) To: musl@lists.openwall.com Original-X-From: musl-return-10660-gllmg-musl=m.gmane.org@lists.openwall.com Thu Oct 20 07:56:09 2016 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1bx6Kg-0005M5-30 for gllmg-musl@m.gmane.org; Thu, 20 Oct 2016 07:56:02 +0200 Original-Received: (qmail 26366 invoked by uid 550); 20 Oct 2016 05:56:03 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 26339 invoked from network); 20 Oct 2016 05:56:02 -0000 Content-Disposition: inline In-Reply-To: <20161011224959.GO28065@port70.net> Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:10647 Archived-At: On Wed, Oct 12, 2016 at 12:49:59AM +0200, Szabolcs Nagy wrote: > in nearest rounding mode exact halfway cases were not following the > round to even rule if the rounding happened at a base 1000000000 digit > boundary of the internal representation and the previous digit was odd. > > e.g. printf("%.0f", 1.5) printed 1 instead of 2. > --- > src/stdio/vfprintf.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/src/stdio/vfprintf.c b/src/stdio/vfprintf.c > index e439a07..ff65295 100644 > --- a/src/stdio/vfprintf.c > +++ b/src/stdio/vfprintf.c > @@ -343,7 +343,8 @@ static int fmt_fp(FILE *f, long double y, int w, int p, int fl, int t) > if (x || d+1!=z) { > long double round = 2/LDBL_EPSILON; > long double small; > - if (*d/i & 1) round += 2; > + if ((*d/i & 1) || (i==1000000000 && d>a && (d[-1]&1))) > + round += 2; > if (x else if (x==i/2 && d+1==z) small=0x1.0p0; > else small=0x1.8p0; > -- > 2.10.0 Thanks, committed. Rich