musl: backport various post-1.1.15 fixes
[openwrt/openwrt.git] / toolchain / musl / patches / 055-fix-strtod-int-optimization-in-non-nearest-rounding-mode.patch
1 From 6ffdc4579ffb34f4aab69ab4c081badabc7c0a9a Mon Sep 17 00:00:00 2001
2 From: Szabolcs Nagy <nsz@port70.net>
3 Date: Sun, 4 Sep 2016 04:51:03 +0200
4 Subject: fix strtod int optimization in non-nearest rounding mode
5
6 the mid-sized integer optimization relies on lnz set up properly
7 to mark the last non-zero decimal digit, but this was not done
8 if the non-zero digit lied outside the KMAX digits of the base
9 10^9 number representation.
10
11 so if the fractional part was a very long list of zeros (>2048*9 on
12 x86) followed by non-zero digits then the integer optimization could
13 kick in discarding the tiny non-zero fraction which can mean wrong
14 result on non-nearest rounding mode.
15
16 strtof, strtod and strtold were all affected.
17 ---
18 src/internal/floatscan.c | 5 ++++-
19 1 file changed, 4 insertions(+), 1 deletion(-)
20
21 diff --git a/src/internal/floatscan.c b/src/internal/floatscan.c
22 index 80305ee..ae09852 100644
23 --- a/src/internal/floatscan.c
24 +++ b/src/internal/floatscan.c
25 @@ -110,7 +110,10 @@ static long double decfloat(FILE *f, int c, int bits, int emin, int sign, int po
26 gotdig=1;
27 } else {
28 dc++;
29 - if (c!='0') x[KMAX-4] |= 1;
30 + if (c!='0') {
31 + lnz = (KMAX-4)*9;
32 + x[KMAX-4] |= 1;
33 + }
34 }
35 }
36 if (!gotrad) lrp=dc;
37 --
38 cgit v0.11.2