]> git.saurik.com Git - apple/libc.git/blame - gdtoa/FreeBSD/gdtoa-hexnan.c.patch
Libc-594.9.5.tar.gz
[apple/libc.git] / gdtoa / FreeBSD / gdtoa-hexnan.c.patch
CommitLineData
34e8f829
A
1--- gdtoa-hexnan.c.orig 2008-03-15 10:08:33.000000000 -0700
2+++ gdtoa-hexnan.c 2008-08-30 17:55:23.000000000 -0700
3@@ -30,6 +30,7 @@ THIS SOFTWARE.
224c7076
A
4 * with " at " changed at "@" and " dot " changed to "."). */
5
6 #include "gdtoaimp.h"
7+#include <fpmath.h>
8
9 static void
10 #ifdef KR_headers
34e8f829 11@@ -57,94 +58,53 @@ hexnan(sp, fpi, x0)
224c7076
A
12 hexnan( CONST char **sp, FPI *fpi, ULong *x0)
13 #endif
14 {
15- ULong c, h, *x, *x1, *xe;
16+ int nbits, len;
17+ char *cp;
18 CONST char *s;
19- int havedig, hd0, i, nbits;
20
21- if (!hexdig['0'])
22- hexdig_init_D2A();
23- nbits = fpi->nbits;
24- x = x0 + (nbits >> kshift);
25- if (nbits & kmask)
26- x++;
27- *--x = 0;
28- x1 = xe = x;
29- havedig = hd0 = i = 0;
30+ if (sp == NULL || *sp == NULL || **sp != '(')
31+ return STRTOG_NaN;
32 s = *sp;
34e8f829
A
33- /* allow optional initial 0x or 0X */
34- while((c = *(CONST unsigned char*)(s+1)) && c <= ' ')
35- ++s;
36- if (s[1] == '0' && (s[2] == 'x' || s[2] == 'X')
37- && *(CONST unsigned char*)(s+3) > ' ')
38- s += 2;
224c7076
A
39- while(c = *(CONST unsigned char*)++s) {
40- if (!(h = hexdig[c])) {
41- if (c <= ' ') {
42- if (hd0 < havedig) {
43- if (x < x1 && i < 8)
44- L_shift(x, x1, i);
45- if (x <= x0) {
46- i = 8;
47- continue;
48- }
49- hd0 = havedig;
50- *--x = 0;
51- x1 = x;
52- i = 0;
53- }
34e8f829
A
54- while(*(CONST unsigned char*)(s+1) <= ' ')
55- ++s;
56- if (s[1] == '0' && (s[2] == 'x' || s[2] == 'X')
57- && *(CONST unsigned char*)(s+3) > ' ')
58- s += 2;
224c7076
A
59- continue;
60- }
61- if (/*(*/ c == ')' && havedig) {
62- *sp = s + 1;
63- break;
64- }
34e8f829
A
65-#ifndef GDTOA_NON_PEDANTIC_NANCHECK
66- do {
67- if (/*(*/ c == ')') {
68- *sp = s + 1;
69- break;
70- }
71- } while(c = *++s);
72-#endif
224c7076
A
73+ if ((cp = strchr(s + 1, ')')) == NULL) {
74+ *sp += strlen(s);
75+ cp = s + 1;
76+ }
77+ else {
78+ len = cp - (s + 1);
79+ cp = alloca(len + 1);
80+ if (!cp)
81 return STRTOG_NaN;
82- }
83- havedig++;
84- if (++i > 8) {
85- if (x <= x0)
86- continue;
87- i = 1;
88- *--x = 0;
89- }
90- *x = (*x << 4) | h & 0xf;
91+ strlcpy(cp, s + 1, len + 1);
92+ *sp += len + 2;
93 }
94- if (!havedig)
95- return STRTOG_NaN;
96- if (x < x1 && i < 8)
97- L_shift(x, x1, i);
98- if (x > x0) {
99- x1 = x0;
100- do *x1++ = *x++;
101- while(x <= xe);
102- do *x1++ = 0;
103- while(x1 <= xe);
104+ nbits = fpi->nbits;
105+ /* a hack */
106+ if (nbits == 52) { /* double */
107+ union IEEEd2bits u;
108+ u.d = nan(cp);
109+ x0[1] = u.bits.manh;
110+ x0[0] = u.bits.manl;
111 }
112- else {
113- /* truncate high-order word if necessary */
114- if ( (i = nbits & (ULbits-1)) !=0)
115- *xe &= ((ULong)0xffffffff) >> (ULbits - i);
116+ else if (nbits < 52) { /* float */
117+ union IEEEf2bits u;
118+ u.f = nanf(cp);
119+ x0[0] = u.bits.man;
120 }
121- for(x1 = xe;; --x1) {
122- if (*x1 != 0)
123- break;
124- if (x1 == x0) {
125- *x1 = 1;
126- break;
127- }
128+ else { /* long double */
129+ union IEEEl2bits u;
130+ u.e = nanl(cp);
131+#if defined(__ppc__) || defined(__ppc64__)
132+ x0[3] = (ULong)(u.bits.manh >> 44);
133+ x0[2] = (ULong)(u.bits.manh >> 12);
134+ x0[1] = ((ULong)u.bits.manh & 0xfff) << 20 | (ULong)(u.bits.manl >> 32);
135+ x0[0] = (ULong)u.bits.manl;
b5d655f7 136+#elif defined(__i386__) || defined(__x86_64__) || defined(__arm__)
224c7076
A
137+ x0[1] = (ULong)u.bits.manh;
138+ x0[0] = (ULong)u.bits.manl;
139+#else
140+#error unsupported architecture
141+#endif
142 }
143+
144 return STRTOG_NaNbits;
145 }