]>
Commit | Line | Data |
---|---|---|
3d9156a7 A |
1 | --- gdtoa-strtopdd.c.orig 2005-01-20 20:12:37.000000000 -0800 |
2 | +++ gdtoa-strtopdd.c 2005-02-17 01:34:59.000000000 -0800 | |
3 | @@ -29,13 +29,25 @@ | |
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, loc) 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 | @@ -49,10 +61,13 @@ | |
32 | typedef union { | |
33 | double d[2]; | |
34 | ULong L[4]; | |
35 | +#ifdef __APPLE__ | |
36 | + long double ld; | |
37 | +#endif /* __APPLE__ */ | |
38 | } U; | |
39 | U *u; | |
40 | ||
41 | - rv = strtodg(s, sp, &fpi, &exp, bits); | |
42 | + rv = strtodg(s, sp, &fpi, &exp, bits, loc); | |
43 | u = (U*)dd; | |
44 | switch(rv & STRTOG_Retmask) { | |
45 | case STRTOG_NoNumber: | |
46 | @@ -101,6 +116,9 @@ | |
47 | } | |
48 | u->L[2+_1] = bits[0]; | |
49 | u->L[2+_0] = bits[1] & 0xfffff | exp << 20; | |
50 | +#ifdef __APPLE__ | |
51 | + fixLDBL(u->ld); | |
52 | +#endif /* __APPLE__ */ | |
53 | break; | |
54 | ||
55 | case STRTOG_Denormal: | |
56 | @@ -124,6 +142,9 @@ | |
57 | u->L[_1] = (bits[2] << i | bits[1] >> j) & 0xffffffffL; | |
58 | u->L[2+_0] = bits[1] & (1L << j) - 1; | |
59 | u->L[2+_1] = bits[0]; | |
60 | +#ifdef __APPLE__ | |
61 | + fixLDBL(u->ld); | |
62 | +#endif /* __APPLE__ */ | |
63 | break; | |
64 | ||
65 | partly_normal: | |
66 | @@ -135,6 +156,9 @@ | |
67 | u->L[_1] = (bits[2] << i | bits[1] >> j) & 0xffffffffL; | |
68 | u->L[2+_0] = bits[1] & (1L << j) - 1; | |
69 | u->L[2+_1] = bits[0]; | |
70 | +#ifdef __APPLE__ | |
71 | + fixLDBL(u->ld); | |
72 | +#endif /* __APPLE__ */ | |
73 | break; | |
74 | } | |
75 | if (i == 0) { | |
76 | @@ -142,6 +166,9 @@ | |
77 | u->L[_1] = bits[1]; | |
78 | u->L[2+_0] = 0; | |
79 | u->L[2+_1] = bits[0]; | |
80 | +#ifdef __APPLE__ | |
81 | + fixLDBL(u->ld); | |
82 | +#endif /* __APPLE__ */ | |
83 | break; | |
84 | } | |
85 | j = 32 - i; | |
86 | @@ -150,6 +177,9 @@ | |
87 | u->L[_1] = (bits[1] << i | bits[0] >> j) & 0xffffffffL; | |
88 | u->L[2+_0] = 0; | |
89 | u->L[2+_1] = bits[0] & (1L << j) - 1; | |
90 | +#ifdef __APPLE__ | |
91 | + fixLDBL(u->ld); | |
92 | +#endif /* __APPLE__ */ | |
93 | break; | |
94 | ||
95 | hardly_normal: | |
96 | @@ -159,20 +189,38 @@ | |
97 | u->L[_1] = (bits[1] << i | bits[0] >> j) & 0xffffffffL; | |
98 | u->L[2+_0] = 0; | |
99 | u->L[2+_1] = bits[0] & (1L << j) - 1; | |
100 | +#ifdef __APPLE__ | |
101 | + fixLDBL(u->ld); | |
102 | +#endif /* __APPLE__ */ | |
103 | break; | |
104 | ||
105 | case STRTOG_Infinite: | |
106 | +#ifdef __APPLE__ | |
107 | + u->L[_0] = 0x7ff00000; | |
108 | + u->L[_1] = u->L[2+_0] = u->L[2+_1] = 0; | |
109 | +#else /* __APPLE__ */ | |
110 | u->L[_0] = u->L[2+_0] = 0x7ff00000; | |
111 | u->L[_1] = u->L[2+_1] = 0; | |
112 | +#endif /* __APPLE__ */ | |
113 | break; | |
114 | ||
115 | case STRTOG_NaN: | |
116 | +#ifdef __APPLE__ | |
117 | + u->L[_0] = 0x7fffffff; | |
118 | + u->L[_1] = (ULong)-1; | |
119 | + u->L[2+_0] = u->L[2+_1] = 0; | |
120 | +#else /* __APPLE__ */ | |
121 | u->L[0] = u->L[2] = d_QNAN0; | |
122 | u->L[1] = u->L[3] = d_QNAN1; | |
123 | +#endif /* __APPLE__ */ | |
124 | } | |
125 | if (rv & STRTOG_Neg) { | |
126 | u->L[ _0] |= 0x80000000L; | |
127 | +#ifdef __APPLE__ | |
128 | + u->L[2+_0] ^= 0x80000000L; | |
129 | +#else /* __APPLE__ */ | |
130 | u->L[2+_0] |= 0x80000000L; | |
131 | +#endif /* __APPLE__ */ | |
132 | } | |
133 | return rv; | |
134 | } |