1112158Sdas/****************************************************************
2112158Sdas
3112158SdasThe author of this software is David M. Gay.
4112158Sdas
5112158SdasCopyright (C) 1998, 2000 by Lucent Technologies
6112158SdasAll Rights Reserved
7112158Sdas
8112158SdasPermission to use, copy, modify, and distribute this software and
9112158Sdasits documentation for any purpose and without fee is hereby
10112158Sdasgranted, provided that the above copyright notice appear in all
11112158Sdascopies and that both that the copyright notice and this
12112158Sdaspermission notice and warranty disclaimer appear in supporting
13112158Sdasdocumentation, and that the name of Lucent or any of its entities
14112158Sdasnot be used in advertising or publicity pertaining to
15112158Sdasdistribution of the software without specific, written prior
16112158Sdaspermission.
17112158Sdas
18112158SdasLUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
19112158SdasINCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
20112158SdasIN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
21112158SdasSPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
22112158SdasWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
23112158SdasIN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
24112158SdasARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
25112158SdasTHIS SOFTWARE.
26112158Sdas
27112158Sdas****************************************************************/
28112158Sdas
29165743Sdas/* Please send bug reports to David M. Gay (dmg at acm dot org,
30165743Sdas * with " at " changed at "@" and " dot " changed to ".").	*/
31112158Sdas
32112158Sdas#include "gdtoaimp.h"
33112158Sdas
34112158Sdas void
35112158Sdas#ifdef KR_headers
36112158SdasULtod(L, bits, exp, k) ULong *L; ULong *bits; Long exp; int k;
37112158Sdas#else
38112158SdasULtod(ULong *L, ULong *bits, Long exp, int k)
39112158Sdas#endif
40112158Sdas{
41112158Sdas	switch(k & STRTOG_Retmask) {
42112158Sdas	  case STRTOG_NoNumber:
43112158Sdas	  case STRTOG_Zero:
44112158Sdas		L[0] = L[1] = 0;
45112158Sdas		break;
46112158Sdas
47112158Sdas	  case STRTOG_Denormal:
48112158Sdas		L[_1] = bits[0];
49112158Sdas		L[_0] = bits[1];
50112158Sdas		break;
51112158Sdas
52112158Sdas	  case STRTOG_Normal:
53112158Sdas	  case STRTOG_NaNbits:
54112158Sdas		L[_1] = bits[0];
55112158Sdas		L[_0] = (bits[1] & ~0x100000) | ((exp + 0x3ff + 52) << 20);
56112158Sdas		break;
57112158Sdas
58112158Sdas	  case STRTOG_Infinite:
59112158Sdas		L[_0] = 0x7ff00000;
60112158Sdas		L[_1] = 0;
61112158Sdas		break;
62112158Sdas
63112158Sdas	  case STRTOG_NaN:
64165743Sdas		L[0] = d_QNAN0;
65165743Sdas		L[1] = d_QNAN1;
66112158Sdas	  }
67112158Sdas	if (k & STRTOG_Neg)
68112158Sdas		L[_0] |= 0x80000000L;
69112158Sdas	}
70112158Sdas
71112158Sdas int
72112158Sdas#ifdef KR_headers
73227753Stheravenstrtord_l(s, sp, rounding, d, locale) CONST char *s; char **sp; int rounding;
74227753Stheravendouble *d; locale_t locale;
75112158Sdas#else
76227753Stheravenstrtord_l(CONST char *s, char **sp, int rounding, double *d, locale_t locale)
77112158Sdas#endif
78112158Sdas{
79112158Sdas	static FPI fpi0 = { 53, 1-1023-53+1, 2046-1023-53+1, 1, SI };
80112158Sdas	FPI *fpi, fpi1;
81112158Sdas	ULong bits[2];
82112158Sdas	Long exp;
83112158Sdas	int k;
84112158Sdas
85112158Sdas	fpi = &fpi0;
86112158Sdas	if (rounding != FPI_Round_near) {
87112158Sdas		fpi1 = fpi0;
88112158Sdas		fpi1.rounding = rounding;
89112158Sdas		fpi = &fpi1;
90112158Sdas		}
91227753Stheraven	k = strtodg_l(s, sp, fpi, &exp, bits, locale);
92112158Sdas	ULtod((ULong*)d, bits, exp, k);
93112158Sdas	return k;
94112158Sdas	}
95227753Stheraven
96