]> git.saurik.com Git - apple/libc.git/blob - gdtoa/FreeBSD/_hdtoa.c.patch
Libc-763.11.tar.gz
[apple/libc.git] / gdtoa / FreeBSD / _hdtoa.c.patch
1 --- _hdtoa.c.orig 2008-09-07 11:38:10.000000000 -0700
2 +++ _hdtoa.c 2008-09-07 12:49:47.000000000 -0700
3 @@ -55,7 +55,7 @@ roundup(char *s0, int ndigits)
4 *s = 1;
5 return (1);
6 }
7 - ++*s;
8 + *s = 0;
9 }
10 ++*s;
11 return (0);
12 @@ -126,12 +126,12 @@ __hdtoa(double d, const char *xdigs, int
13 static const int sigfigs = (DBL_MANT_DIG + 3) / 4;
14 union IEEEd2bits u;
15 char *s, *s0;
16 - int bufsize;
17 + int bufsize, f;
18
19 u.d = d;
20 *sign = u.bits.sign;
21
22 - switch (fpclassify(d)) {
23 + switch (f = fpclassify(d)) {
24 case FP_NORMAL:
25 *decpt = u.bits.exp - DBL_ADJ;
26 break;
27 @@ -149,7 +149,7 @@ __hdtoa(double d, const char *xdigs, int
28 *decpt = INT_MAX;
29 return (nrv_alloc(NANSTR, rve, sizeof(NANSTR) - 1));
30 default:
31 - abort();
32 + LIBC_ABORT("fpclassify returned %d", f);
33 }
34
35 /* FP_NORMAL or FP_SUBNORMAL */
36 @@ -210,6 +210,7 @@ __hdtoa(double d, const char *xdigs, int
37 return (s0);
38 }
39
40 +#ifndef LDBL_COMPAT
41 #if (LDBL_MANT_DIG > DBL_MANT_DIG)
42
43 /*
44 @@ -222,13 +223,18 @@ __hldtoa(long double e, const char *xdig
45 static const int sigfigs = (LDBL_MANT_DIG + 3) / 4;
46 union IEEEl2bits u;
47 char *s, *s0;
48 - int bufsize;
49 + int bufsize, f;
50 +#ifdef LDBL_HEAD_TAIL_PAIR
51 + uint32_t bits[4];
52 + int i, pos;
53 +#endif /* LDBL_HEAD_TAIL_PAIR */
54
55 u.e = e;
56 *sign = u.bits.sign;
57
58 - switch (fpclassify(e)) {
59 + switch (f = fpclassify(e)) {
60 case FP_NORMAL:
61 + case FP_SUPERNORMAL:
62 *decpt = u.bits.exp - LDBL_ADJ;
63 break;
64 case FP_ZERO:
65 @@ -245,7 +251,7 @@ __hldtoa(long double e, const char *xdig
66 *decpt = INT_MAX;
67 return (nrv_alloc(NANSTR, rve, sizeof(NANSTR) - 1));
68 default:
69 - abort();
70 + LIBC_ABORT("fpclassify returned %d", f);
71 }
72
73 /* FP_NORMAL or FP_SUBNORMAL */
74 @@ -270,6 +276,19 @@ __hldtoa(long double e, const char *xdig
75 */
76 for (s = s0 + bufsize - 1; s > s0 + sigfigs - 1; s--)
77 *s = 0;
78 +#ifdef LDBL_HEAD_TAIL_PAIR
79 + *decpt -= _ldbl2array32dd(u, bits);
80 + i = 0;
81 + pos = 8;
82 + for (; s > s0; s--) {
83 + *s = bits[i] & 0xf;
84 + bits[i] >>= 4;
85 + if (--pos <= 0) {
86 + i++;
87 + pos = 8;
88 + }
89 + }
90 +#else /* LDBL_HEAD_TAIL_PAIR */
91 for (; s > s0 + sigfigs - (LDBL_MANL_SIZE / 4) - 1 && s > s0; s--) {
92 *s = u.bits.manl & 0xf;
93 u.bits.manl >>= 4;
94 @@ -278,6 +297,7 @@ __hldtoa(long double e, const char *xdig
95 *s = u.bits.manh & 0xf;
96 u.bits.manh >>= 4;
97 }
98 +#endif /* LDBL_HEAD_TAIL_PAIR */
99
100 /*
101 * At this point, we have snarfed all the bits in the
102 @@ -285,7 +305,11 @@ __hldtoa(long double e, const char *xdig
103 * (partial) nibble, which is dealt with by the next
104 * statement. We also tack on the implicit normalization bit.
105 */
106 +#ifdef LDBL_HEAD_TAIL_PAIR
107 + *s = bits[i];
108 +#else /* LDBL_HEAD_TAIL_PAIR */
109 *s = u.bits.manh | (1U << ((LDBL_MANT_DIG - 1) % 4));
110 +#endif /* LDBL_HEAD_TAIL_PAIR */
111
112 /* If ndigits < 0, we are expected to auto-size the precision. */
113 if (ndigits < 0) {
114 @@ -317,3 +341,4 @@ __hldtoa(long double e, const char *xdig
115 }
116
117 #endif /* (LDBL_MANT_DIG == DBL_MANT_DIG) */
118 +#endif /* !LDBL_COMPAT */