]> git.saurik.com Git - apple/libc.git/blob - gdtoa/FreeBSD/gdtoa-strtodg.c.patch
Libc-498.1.1.tar.gz
[apple/libc.git] / gdtoa / FreeBSD / gdtoa-strtodg.c.patch
1 --- gdtoa-strtodg.c.orig 2007-10-04 15:00:21.000000000 -0700
2 +++ gdtoa-strtodg.c 2007-10-04 17:49:06.000000000 -0700
3 @@ -29,13 +29,29 @@
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 USE_LOCALE
12 #include "locale.h"
13 #endif
14
15 - static CONST int
16 +#define fivesbits __fivesbits_D2A
17 +#define all_on __all_on_D2A
18 +#define set_ones __set_ones_D2A
19 +#define rvOK __rvOK_D2A
20 +#define mantbits __mantbits_D2A
21 +
22 +#ifdef BUILDING_VARIANT
23 +extern CONST int fivesbits[];
24 +int all_on(Bigint *b, int n);
25 +Bigint *set_ones(Bigint *b, int n);
26 +int rvOK(double d, FPI *fpi, Long *exp, ULong *bits, int exact, int rd, int *irv);
27 +int mantbits(double d);
28 +#else /* !BUILDING_VARIANT */
29 +
30 + __private_extern__ CONST int
31 fivesbits[] = { 0, 3, 5, 7, 10, 12, 14, 17, 19, 21,
32 24, 26, 28, 31, 33, 35, 38, 40, 42, 45,
33 47, 49, 52
34 @@ -122,7 +138,7 @@
35 return STRTOG_Inexlo;
36 }
37
38 - static int
39 + __private_extern__ int
40 #ifdef KR_headers
41 all_on(b, n) Bigint *b; int n;
42 #else
43 @@ -169,7 +185,7 @@
44 return b;
45 }
46
47 - static int
48 + __private_extern__ int
49 rvOK
50 #ifdef KR_headers
51 (d, fpi, exp, bits, exact, rd, irv)
52 @@ -290,7 +306,7 @@
53 return rv;
54 }
55
56 - static int
57 + __private_extern__ int
58 #ifdef KR_headers
59 mantbits(d) double d;
60 #else
61 @@ -313,13 +329,15 @@
62 return P - 32 - lo0bits(&L);
63 }
64
65 +#endif /* BUILDING_VARIANT */
66 +
67 int
68 strtodg
69 #ifdef KR_headers
70 - (s00, se, fpi, exp, bits)
71 - CONST char *s00; char **se; FPI *fpi; Long *exp; ULong *bits;
72 + (s00, se, fpi, exp, bits, loc)
73 + CONST char *s00; char **se; FPI *fpi; Long *exp; ULong *bits; locale_t loc;
74 #else
75 - (CONST char *s00, char **se, FPI *fpi, Long *exp, ULong *bits)
76 + (CONST char *s00, char **se, FPI *fpi, Long *exp, ULong *bits, locale_t loc)
77 #endif
78 {
79 int abe, abits, asub;
80 @@ -332,6 +350,10 @@
81 Long L;
82 ULong y, z;
83 Bigint *ab, *bb, *bb1, *bd, *bd0, *bs, *delta, *rvb, *rvb0;
84 +#ifdef USE_LOCALE
85 + char *decimal_point;
86 + int decimal_point_len;
87 +#endif /* USE_LOCALE */
88
89 irv = STRTOG_Zero;
90 denorm = sign = nz0 = nz = 0;
91 @@ -367,7 +389,7 @@
92 switch(s[1]) {
93 case 'x':
94 case 'X':
95 - irv = gethex(&s, fpi, exp, &rvb, sign);
96 + irv = gethex(&s, fpi, exp, &rvb, sign, loc);
97 if (irv == STRTOG_NoNumber) {
98 s = s00;
99 sign = 0;
100 @@ -389,14 +411,22 @@
101 else if (nd < 16)
102 z = 10*z + c - '0';
103 nd0 = nd;
104 + NORMALIZE_LOCALE(loc);
105 #ifdef USE_LOCALE
106 - if (c == *localeconv()->decimal_point)
107 + decimal_point = localeconv_l(loc)->decimal_point;
108 + decimal_point_len = strlen(decimal_point);
109 + if (strncmp(s, decimal_point, decimal_point_len) == 0)
110 #else
111 if (c == '.')
112 #endif
113 {
114 decpt = 1;
115 +#ifdef USE_LOCALE
116 + s += decimal_point_len;
117 + c = *s;
118 +#else
119 c = *++s;
120 +#endif
121 if (!nd) {
122 for(; c == '0'; c = *++s)
123 nz++;
124 @@ -668,6 +698,9 @@
125 rvb->x[0] = 0;
126 *exp = emin;
127 irv = STRTOG_Underflow | STRTOG_Inexlo;
128 +#ifndef NO_ERRNO
129 + errno = ERANGE;
130 +#endif
131 goto ret;
132 }
133 rvb->x[0] = rvb->wds = rvbits = 1;
134 @@ -684,7 +717,11 @@
135
136 /* Put digits into bd: true value = bd * 10^e */
137
138 - bd0 = s2b(s0, nd0, nd, y);
139 +#ifdef USE_LOCALE
140 + bd0 = s2b(s0, nd0, nd, y, decimal_point_len);
141 +#else
142 + bd0 = s2b(s0, nd0, nd, y, 1);
143 +#endif
144
145 for(;;) {
146 bd = Balloc(bd0->k);
147 @@ -824,7 +861,7 @@
148 rvb = increment(rvb);
149 if ( (j = rvbits & kmask) !=0)
150 j = ULbits - j;
151 - if (hi0bits(rvb->x[(rvb->wds - 1) >> kshift])
152 + if (hi0bits(rvb->x[rvb->wds - 1])
153 != j)
154 rvbits++;
155 irv = STRTOG_Normal | STRTOG_Inexhi;
156 @@ -1008,5 +1045,9 @@
157 copybits(bits, nbits, rvb);
158 Bfree(rvb);
159 }
160 +#if !defined(NO_ERRNO) && __DARWIN_UNIX03
161 + if (irv & STRTOG_Underflow)
162 + errno = ERANGE;
163 +#endif
164 return irv;
165 }