From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/4825 Path: news.gmane.org!not-for-mail From: Szabolcs Nagy Newsgroups: gmane.linux.lib.musl.general Subject: Re: printf issues Date: Mon, 7 Apr 2014 17:36:11 +0200 Message-ID: <20140407153611.GM3034@port70.net> References: <20140404185413.GH3034@port70.net> <20140404210837.GS26358@brightrain.aerifal.cx> <20140407072930.GB26358@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1396884991 14259 80.91.229.3 (7 Apr 2014 15:36:31 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 7 Apr 2014 15:36:31 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-4829-gllmg-musl=m.gmane.org@lists.openwall.com Mon Apr 07 17:36:25 2014 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1WXBay-0007gi-Aq for gllmg-musl@plane.gmane.org; Mon, 07 Apr 2014 17:36:24 +0200 Original-Received: (qmail 18240 invoked by uid 550); 7 Apr 2014 15:36:22 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 18232 invoked from network); 7 Apr 2014 15:36:22 -0000 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Xref: news.gmane.org gmane.linux.lib.musl.general:4825 Archived-At: * Morten Welinder [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