]>
Commit | Line | Data |
---|---|---|
224c7076 A |
1 | --- gdtoa-hexnan.c.orig 2005-01-20 20:12:36.000000000 -0800 |
2 | +++ gdtoa-hexnan.c 2005-06-10 17:43:17.000000000 -0700 | |
3 | @@ -30,6 +30,7 @@ | |
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 | |
11 | @@ -57,75 +58,53 @@ | |
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; | |
33 | - while(c = *(CONST unsigned char*)++s) { | |
34 | - if (!(h = hexdig[c])) { | |
35 | - if (c <= ' ') { | |
36 | - if (hd0 < havedig) { | |
37 | - if (x < x1 && i < 8) | |
38 | - L_shift(x, x1, i); | |
39 | - if (x <= x0) { | |
40 | - i = 8; | |
41 | - continue; | |
42 | - } | |
43 | - hd0 = havedig; | |
44 | - *--x = 0; | |
45 | - x1 = x; | |
46 | - i = 0; | |
47 | - } | |
48 | - continue; | |
49 | - } | |
50 | - if (/*(*/ c == ')' && havedig) { | |
51 | - *sp = s + 1; | |
52 | - break; | |
53 | - } | |
54 | + if ((cp = strchr(s + 1, ')')) == NULL) { | |
55 | + *sp += strlen(s); | |
56 | + cp = s + 1; | |
57 | + } | |
58 | + else { | |
59 | + len = cp - (s + 1); | |
60 | + cp = alloca(len + 1); | |
61 | + if (!cp) | |
62 | return STRTOG_NaN; | |
63 | - } | |
64 | - havedig++; | |
65 | - if (++i > 8) { | |
66 | - if (x <= x0) | |
67 | - continue; | |
68 | - i = 1; | |
69 | - *--x = 0; | |
70 | - } | |
71 | - *x = (*x << 4) | h & 0xf; | |
72 | + strlcpy(cp, s + 1, len + 1); | |
73 | + *sp += len + 2; | |
74 | } | |
75 | - if (!havedig) | |
76 | - return STRTOG_NaN; | |
77 | - if (x < x1 && i < 8) | |
78 | - L_shift(x, x1, i); | |
79 | - if (x > x0) { | |
80 | - x1 = x0; | |
81 | - do *x1++ = *x++; | |
82 | - while(x <= xe); | |
83 | - do *x1++ = 0; | |
84 | - while(x1 <= xe); | |
85 | + nbits = fpi->nbits; | |
86 | + /* a hack */ | |
87 | + if (nbits == 52) { /* double */ | |
88 | + union IEEEd2bits u; | |
89 | + u.d = nan(cp); | |
90 | + x0[1] = u.bits.manh; | |
91 | + x0[0] = u.bits.manl; | |
92 | } | |
93 | - else { | |
94 | - /* truncate high-order word if necessary */ | |
95 | - if ( (i = nbits & (ULbits-1)) !=0) | |
96 | - *xe &= ((ULong)0xffffffff) >> (ULbits - i); | |
97 | + else if (nbits < 52) { /* float */ | |
98 | + union IEEEf2bits u; | |
99 | + u.f = nanf(cp); | |
100 | + x0[0] = u.bits.man; | |
101 | } | |
102 | - for(x1 = xe;; --x1) { | |
103 | - if (*x1 != 0) | |
104 | - break; | |
105 | - if (x1 == x0) { | |
106 | - *x1 = 1; | |
107 | - break; | |
108 | - } | |
109 | + else { /* long double */ | |
110 | + union IEEEl2bits u; | |
111 | + u.e = nanl(cp); | |
112 | +#if defined(__ppc__) || defined(__ppc64__) | |
113 | + x0[3] = (ULong)(u.bits.manh >> 44); | |
114 | + x0[2] = (ULong)(u.bits.manh >> 12); | |
115 | + x0[1] = ((ULong)u.bits.manh & 0xfff) << 20 | (ULong)(u.bits.manl >> 32); | |
116 | + x0[0] = (ULong)u.bits.manl; | |
117 | +#elif defined(__i386__) || defined(__x86_64__) | |
118 | + x0[1] = (ULong)u.bits.manh; | |
119 | + x0[0] = (ULong)u.bits.manl; | |
120 | +#else | |
121 | +#error unsupported architecture | |
122 | +#endif | |
123 | } | |
124 | + | |
125 | return STRTOG_NaNbits; | |
126 | } |