]> git.saurik.com Git - apple/libc.git/blob - gdtoa/FreeBSD/gdtoa-strtopdd.c.patch
Libc-498.1.7.tar.gz
[apple/libc.git] / gdtoa / FreeBSD / gdtoa-strtopdd.c.patch
1 --- gdtoa-strtopdd.c.orig 2007-04-03 12:19:28.000000000 -0700
2 +++ gdtoa-strtopdd.c 2007-04-06 12:53:25.000000000 -0700
3 @@ -29,19 +29,31 @@
4 /* Please send bug reports to David M. Gay (dmg at acm dot org,
5 * with " at " changed at "@" and " dot " changed to "."). */
6
7 +#include "xlocale_private.h"
8 +
9 #include "gdtoaimp.h"
10
11 +#ifdef __APPLE__
12 +/*
13 + * IEEE specifies that the most significant (head) double is required to
14 + * be equal to the long double rounded to the nearest double, so that means
15 + * the tail double might be the opposite sign as the head. We can do this
16 + * adding (long double)0 to the number, which will fix it up.
17 + */
18 +#define fixLDBL(x) ((x) += 0.L)
19 +#endif /* __APPLE__ */
20 +
21 int
22 #ifdef KR_headers
23 -strtopdd(s, sp, dd) CONST char *s; char **sp; double *dd;
24 +strtopdd(s, sp, dd) CONST char *s; char **sp; double *dd; locale_t loc;
25 #else
26 -strtopdd(CONST char *s, char **sp, double *dd)
27 +strtopdd(CONST char *s, char **sp, double *dd, locale_t loc)
28 #endif
29 {
30 #ifdef Sudden_Underflow
31 - static FPI fpi = { 106, 1-1023, 2046-1023-106+1, 1, 1 };
32 + static FPI fpi0 = { 106, 1-1023, 2046-1023-106+1, 1, 1 };
33 #else
34 - static FPI fpi = { 106, 1-1023-53+1, 2046-1023-106+1, 1, 0 };
35 + static FPI fpi0 = { 106, 1-1023-53+1, 2046-1023-106+1, 1, 0 };
36 #endif
37 ULong bits[4];
38 Long exp;
39 @@ -49,13 +61,30 @@
40 typedef union {
41 double d[2];
42 ULong L[4];
43 +#ifdef __APPLE__
44 + long double ld;
45 +#endif /* __APPLE__ */
46 } U;
47 U *u;
48 + FPI *fpi = &fpi0, fpi1;
49 +#ifdef Honor_FLT_ROUNDS
50 + int rounding = Flt_Rounds;
51 +#endif
52
53 - rv = strtodg(s, sp, &fpi, &exp, bits);
54 +#ifdef Honor_FLT_ROUNDS
55 + if (rounding != fpi0.rounding) {
56 + fpi1 = fpi0; /* for thread safety */
57 + fpi1.rounding = rounding;
58 + fpi = &fpi1;
59 + }
60 +#endif /* Honor_FLT_ROUNDS */
61 + rv = strtodg(s, sp, fpi, &exp, bits, loc);
62 u = (U*)dd;
63 switch(rv & STRTOG_Retmask) {
64 case STRTOG_NoNumber:
65 + u->d[0] = u->d[1] = 0.;
66 + return rv; // avoid setting sign
67 +
68 case STRTOG_Zero:
69 u->d[0] = u->d[1] = 0.;
70 break;
71 @@ -101,6 +130,9 @@
72 }
73 u->L[2+_1] = bits[0];
74 u->L[2+_0] = bits[1] & 0xfffff | exp << 20;
75 +#ifdef __APPLE__
76 + fixLDBL(u->ld);
77 +#endif /* __APPLE__ */
78 break;
79
80 case STRTOG_Denormal:
81 @@ -124,6 +156,9 @@
82 u->L[_1] = (bits[2] << i | bits[1] >> j) & 0xffffffffL;
83 u->L[2+_0] = bits[1] & (1L << j) - 1;
84 u->L[2+_1] = bits[0];
85 +#ifdef __APPLE__
86 + fixLDBL(u->ld);
87 +#endif /* __APPLE__ */
88 break;
89
90 partly_normal:
91 @@ -135,6 +170,9 @@
92 u->L[_1] = (bits[2] << i | bits[1] >> j) & 0xffffffffL;
93 u->L[2+_0] = bits[1] & (1L << j) - 1;
94 u->L[2+_1] = bits[0];
95 +#ifdef __APPLE__
96 + fixLDBL(u->ld);
97 +#endif /* __APPLE__ */
98 break;
99 }
100 if (i == 0) {
101 @@ -142,6 +180,9 @@
102 u->L[_1] = bits[1];
103 u->L[2+_0] = 0;
104 u->L[2+_1] = bits[0];
105 +#ifdef __APPLE__
106 + fixLDBL(u->ld);
107 +#endif /* __APPLE__ */
108 break;
109 }
110 j = 32 - i;
111 @@ -150,6 +191,9 @@
112 u->L[_1] = (bits[1] << i | bits[0] >> j) & 0xffffffffL;
113 u->L[2+_0] = 0;
114 u->L[2+_1] = bits[0] & (1L << j) - 1;
115 +#ifdef __APPLE__
116 + fixLDBL(u->ld);
117 +#endif /* __APPLE__ */
118 break;
119
120 hardly_normal:
121 @@ -159,20 +203,44 @@
122 u->L[_1] = (bits[1] << i | bits[0] >> j) & 0xffffffffL;
123 u->L[2+_0] = 0;
124 u->L[2+_1] = bits[0] & (1L << j) - 1;
125 +#ifdef __APPLE__
126 + fixLDBL(u->ld);
127 +#endif /* __APPLE__ */
128 break;
129
130 case STRTOG_Infinite:
131 +#ifdef __APPLE__
132 + u->L[_0] = 0x7ff00000;
133 + u->L[_1] = u->L[2+_0] = u->L[2+_1] = 0;
134 +#else /* __APPLE__ */
135 u->L[_0] = u->L[2+_0] = 0x7ff00000;
136 u->L[_1] = u->L[2+_1] = 0;
137 +#endif /* __APPLE__ */
138 break;
139
140 case STRTOG_NaN:
141 +#ifdef __APPLE__
142 + u->L[0] = d_QNAN0;
143 + u->L[1] = d_QNAN1;
144 + u->L[2] = u->L[3] = 0;
145 +#else /* __APPLE__ */
146 u->L[0] = u->L[2] = d_QNAN0;
147 u->L[1] = u->L[3] = d_QNAN1;
148 +#endif /* __APPLE__ */
149 +#ifdef __APPLE__
150 + case STRTOG_NaNbits:
151 + u->L[0] = d_QNAN0 | ((bits[2] >> 20 | bits[3] << 12) & 0xfffff);
152 + u->L[1] = d_QNAN1 | bits[1] >> 20 | bits[2] << 12;
153 + u->L[2] = u->L[3] = 0;
154 +#endif /* __APPLE__ */
155 }
156 if (rv & STRTOG_Neg) {
157 u->L[ _0] |= 0x80000000L;
158 +#ifdef __APPLE__
159 + u->L[2+_0] ^= 0x80000000L;
160 +#else /* __APPLE__ */
161 u->L[2+_0] |= 0x80000000L;
162 +#endif /* __APPLE__ */
163 }
164 return rv;
165 }