From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/10420 Path: news.gmane.org!.POSTED!not-for-mail From: Szabolcs Nagy Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH][RFC] fix strtod int optimization in non-nearest rounding mode Date: Sun, 4 Sep 2016 04:51:03 +0200 Message-ID: <20160904025102.GN1280@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 1472957485 10819 195.159.176.226 (4 Sep 2016 02:51:25 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 4 Sep 2016 02:51:25 +0000 (UTC) User-Agent: Mutt/1.6.0 (2016-04-01) To: musl@lists.openwall.com Original-X-From: musl-return-10433-gllmg-musl=m.gmane.org@lists.openwall.com Sun Sep 04 04:51:22 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 1bgNWd-0001jU-To for gllmg-musl@m.gmane.org; Sun, 04 Sep 2016 04:51:16 +0200 Original-Received: (qmail 3263 invoked by uid 550); 4 Sep 2016 02:51:15 -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 3234 invoked from network); 4 Sep 2016 02:51:14 -0000 Mail-Followup-To: musl@lists.openwall.com Content-Disposition: inline Xref: news.gmane.org gmane.linux.lib.musl.general:10420 Archived-At: the mid-sized integer optimization relies on lnz set up properly to mark the last non-zero decimal digit, but this was not done if the non-zero digit lied outside the KMAX digits of the base 10^9 number representation. so if the fractional part was a very long list of zeros (>2048*9 on x86) followed by non-zero digits then the integer optimization could kick in discarding the tiny non-zero fraction which can mean wrong result on non-nearest rounding mode. strtof, strtod and strtold were all affected. --- the dc counter is long long, but lnz is int, so this is not correct on 64bit targets where dc can be >INT_MAX, probably lnz should be just set to KMAX*9 or similar in this case. src/internal/floatscan.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/internal/floatscan.c b/src/internal/floatscan.c index 66d01ef..682b80a 100644 --- a/src/internal/floatscan.c +++ b/src/internal/floatscan.c @@ -110,7 +110,10 @@ static long double decfloat(FILE *f, int c, int bits, int emin, int sign, int po gotdig=1; } else { dc++; - if (c!='0') x[KMAX-4] |= 1; + if (c!='0') { + lnz = dc; + x[KMAX-4] |= 1; + } } } if (!gotrad) lrp=dc; -- 2.9.3