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