From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/10628 Path: news.gmane.org!.POSTED!not-for-mail From: Szabolcs Nagy Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH] fix float formatting of some exact halfway cases Date: Wed, 12 Oct 2016 00:49:59 +0200 Message-ID: <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 1476226225 6152 195.159.176.226 (11 Oct 2016 22:50:25 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 11 Oct 2016 22:50:25 +0000 (UTC) User-Agent: Mutt/1.6.0 (2016-04-01) To: musl@lists.openwall.com Original-X-From: musl-return-10641-gllmg-musl=m.gmane.org@lists.openwall.com Wed Oct 12 00:50:21 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 1bu5sC-0008He-9E for gllmg-musl@m.gmane.org; Wed, 12 Oct 2016 00:50:12 +0200 Original-Received: (qmail 29886 invoked by uid 550); 11 Oct 2016 22:50:12 -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 29857 invoked from network); 11 Oct 2016 22:50:11 -0000 Mail-Followup-To: musl@lists.openwall.com Content-Disposition: inline Xref: news.gmane.org gmane.linux.lib.musl.general:10628 Archived-At: 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