master
 1/****************************************************************
 2
 3The author of this software is David M. Gay.
 4
 5Copyright (C) 2004 by David M. Gay.
 6All Rights Reserved
 7Based on material in the rest of /netlib/fp/gdota.tar.gz,
 8which is copyright (C) 1998, 2000 by Lucent Technologies.
 9
10Permission to use, copy, modify, and distribute this software and
11its documentation for any purpose and without fee is hereby
12granted, provided that the above copyright notice appear in all
13copies and that both that the copyright notice and this
14permission notice and warranty disclaimer appear in supporting
15documentation, and that the name of Lucent or any of its entities
16not be used in advertising or publicity pertaining to
17distribution of the software without specific, written prior
18permission.
19
20LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
21INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
22IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
23SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
24WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
25IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
26ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
27THIS SOFTWARE.
28
29****************************************************************/
30
31/* This is a variant of strtod that works on Intel ia32 systems */
32/* with the default extended-precision arithmetic -- it does not */
33/* require setting the precision control to 53 bits.  */
34
35/* Please send bug reports to David M. Gay (dmg at acm dot org,
36 * with " at " changed at "@" and " dot " changed to ".").	*/
37
38#include "gdtoaimp.h"
39
40double __strtod (const char *s, char **sp)
41{
42	static FPI fpi = { 53, 1-1023-53+1, 2046-1023-53+1, 1, SI, Int_max /*unused*/ };
43	ULong bits[2];
44	Long expo;
45	int k;
46	union { ULong L[2]; double d; } u;
47
48	k = __strtodg (s, sp, &fpi, &expo, bits);
49	switch(k & STRTOG_Retmask) {
50	  case STRTOG_NoNumber:
51	  case STRTOG_Zero:
52		u.L[0] = u.L[1] = 0;
53		break;
54
55	  case STRTOG_Normal:
56		u.L[_1] = bits[0];
57		u.L[_0] = (bits[1] & ~0x100000) | ((expo + 0x3ff + 52) << 20);
58		break;
59
60	  case STRTOG_Denormal:
61		u.L[_1] = bits[0];
62		u.L[_0] = bits[1];
63		break;
64
65	  case STRTOG_Infinite:
66		u.L[_0] = 0x7ff00000;
67		u.L[_1] = 0;
68		break;
69
70	  case STRTOG_NaN:
71		u.L[_1] = d_QNAN0;
72		u.L[_0] = d_QNAN1;
73		break;
74
75	  case STRTOG_NaNbits:
76		u.L[_0] = 0x7ff00000 | bits[1];
77		u.L[_1] = bits[0];
78	}
79	if (k & STRTOG_Neg)
80		u.L[_0] |= 0x80000000L;
81	return u.d;
82}
83
84double __cdecl
85__mingw_strtod (const char * __restrict__ src, char ** __restrict__ endptr)
86  __attribute__((alias("__strtod")));
87
88#if __SIZEOF_LONG_DOUBLE__ == __SIZEOF_DOUBLE__
89/* For systems other than x86, where long double == double, provide the
90 * long double functions as aliases to __strtod. */
91
92long double __cdecl
93__mingw_strtold (const char * __restrict__ src, char ** __restrict__ endptr)
94  __attribute__((alias("__strtod")));
95#endif