]>
git.saurik.com Git - apple/libc.git/blob - gdtoa/FreeBSD/gdtoa-strtopdd.c
1 /****************************************************************
3 The author of this software is David M. Gay.
5 Copyright (C) 1998, 2000 by Lucent Technologies
8 Permission to use, copy, modify, and distribute this software and
9 its documentation for any purpose and without fee is hereby
10 granted, provided that the above copyright notice appear in all
11 copies and that both that the copyright notice and this
12 permission notice and warranty disclaimer appear in supporting
13 documentation, and that the name of Lucent or any of its entities
14 not be used in advertising or publicity pertaining to
15 distribution of the software without specific, written prior
18 LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
19 INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
20 IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
21 SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
22 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
23 IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
24 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
27 ****************************************************************/
29 /* Please send bug reports to David M. Gay (dmg at acm dot org,
30 * with " at " changed at "@" and " dot " changed to "."). */
32 #include "xlocale_private.h"
38 * IEEE specifies that the most significant (head) double is required to
39 * be equal to the long double rounded to the nearest double, so that means
40 * the tail double might be the opposite sign as the head. We can do this
41 * adding (long double)0 to the number, which will fix it up.
43 #define fixLDBL(x) ((x) += 0.L)
44 #endif /* __APPLE__ */
48 strtopdd(s
, sp
, dd
, loc
) CONST
char *s
; char **sp
; double *dd
; locale_t loc
;
50 strtopdd(CONST
char *s
, char **sp
, double *dd
, locale_t loc
)
53 #ifdef Sudden_Underflow
54 static FPI fpi0
= { 106, 1-1023, 2046-1023-106+1, 1, 1 };
56 static FPI fpi0
= { 106, 1-1023-53+1, 2046-1023-106+1, 1, 0 };
66 #endif /* __APPLE__ */
69 #ifdef Honor_FLT_ROUNDS
70 #include "gdtoa_fltrnds.h"
75 rv
= strtodg(s
, sp
, fpi
, &exp
, bits
, loc
);
77 switch(rv
& STRTOG_Retmask
) {
79 u
->d
[0] = u
->d
[1] = 0.;
80 return rv
; // avoid setting sign
83 u
->d
[0] = u
->d
[1] = 0.;
87 u
->L
[_1
] = (bits
[1] >> 21 | bits
[2] << 11) & 0xffffffffL
;
88 u
->L
[_0
] = (bits
[2] >> 21) | ((bits
[3] << 11) & 0xfffff)
89 | ((exp
+ 0x3ff + 105) << 20);
91 if (bits
[1] &= 0x1fffff) {
92 i
= hi0bits(bits
[1]) - 11;
100 bits
[1] = bits
[1] << i
| bits
[0] >> (32-i
);
101 bits
[0] = bits
[0] << i
& 0xffffffffL
;
105 i
= hi0bits(bits
[0]) + 21;
113 bits
[1] = bits
[0] >> (32 - i
);
114 bits
[0] = bits
[0] << i
& 0xffffffffL
;
117 bits
[1] = bits
[0] << (i
- 32);
122 u
->L
[2] = u
->L
[3] = 0;
125 u
->L
[2+_1
] = bits
[0];
126 u
->L
[2+_0
] = (bits
[1] & 0xfffff) | (exp
<< 20);
129 #endif /* __APPLE__ */
132 case STRTOG_Denormal
:
137 if (bits
[1] & 0xffe00000)
139 /* completely denormal */
140 u
->L
[2] = u
->L
[3] = 0;
146 i
= hi0bits(bits
[3]) - 11; /* i >= 12 */
148 u
->L
[_0
] = ((bits
[3] << i
| bits
[2] >> j
) & 0xfffff)
150 u
->L
[_1
] = (bits
[2] << i
| bits
[1] >> j
) & 0xffffffffL
;
151 u
->L
[2+_0
] = bits
[1] & ((1L << j
) - 1);
152 u
->L
[2+_1
] = bits
[0];
155 #endif /* __APPLE__ */
159 i
= hi0bits(bits
[2]) - 11;
163 u
->L
[_0
] = (bits
[2] >> j
& 0xfffff) | (33 + j
) << 20;
164 u
->L
[_1
] = ((bits
[2] << i
) | (bits
[1] >> j
)) & 0xffffffffL
;
165 u
->L
[2+_0
] = bits
[1] & ((1L << j
) - 1);
166 u
->L
[2+_1
] = bits
[0];
169 #endif /* __APPLE__ */
173 u
->L
[_0
] = (bits
[2] & 0xfffff) | (33 << 20);
176 u
->L
[2+_1
] = bits
[0];
179 #endif /* __APPLE__ */
183 u
->L
[_0
] = (((bits
[2] << i
) | (bits
[1] >> j
)) & 0xfffff)
185 u
->L
[_1
] = (bits
[1] << i
| bits
[0] >> j
) & 0xffffffffL
;
187 u
->L
[2+_1
] = bits
[0] & ((1L << j
) - 1);
190 #endif /* __APPLE__ */
194 j
= 11 - hi0bits(bits
[1]);
196 u
->L
[_0
] = (bits
[1] >> j
& 0xfffff) | ((j
+ 1) << 20);
197 u
->L
[_1
] = (bits
[1] << i
| bits
[0] >> j
) & 0xffffffffL
;
199 u
->L
[2+_1
] = bits
[0] & ((1L << j
) - 1);
202 #endif /* __APPLE__ */
205 case STRTOG_Infinite
:
207 u
->L
[_0
] = 0x7ff00000;
208 u
->L
[_1
] = u
->L
[2+_0
] = u
->L
[2+_1
] = 0;
209 #else /* __APPLE__ */
210 u
->L
[_0
] = u
->L
[2+_0
] = 0x7ff00000;
211 u
->L
[_1
] = u
->L
[2+_1
] = 0;
212 #endif /* __APPLE__ */
219 u
->L
[2] = u
->L
[3] = 0;
220 #else /* __APPLE__ */
221 u
->L
[0] = u
->L
[2] = d_QNAN0
;
222 u
->L
[1] = u
->L
[3] = d_QNAN1
;
223 #endif /* __APPLE__ */
227 u
->L
[0] = d_QNAN0
| ((bits
[2] >> 20 | bits
[3] << 12) & 0xfffff);
228 u
->L
[1] = d_QNAN1
| bits
[1] >> 20 | bits
[2] << 12;
229 u
->L
[2] = u
->L
[3] = 0;
230 #endif /* __APPLE__ */
232 if (rv
& STRTOG_Neg
) {
233 u
->L
[ _0
] |= 0x80000000L
;
235 u
->L
[2+_0
] ^= 0x80000000L
;
236 #else /* __APPLE__ */
237 u
->L
[2+_0
] |= 0x80000000L
;
238 #endif /* __APPLE__ */