1cc36ccd1SDavid Schultz /****************************************************************
2cc36ccd1SDavid Schultz
3cc36ccd1SDavid Schultz The author of this software is David M. Gay.
4cc36ccd1SDavid Schultz
5cc36ccd1SDavid Schultz Copyright (C) 1998, 2000 by Lucent Technologies
6cc36ccd1SDavid Schultz All Rights Reserved
7cc36ccd1SDavid Schultz
8cc36ccd1SDavid Schultz Permission to use, copy, modify, and distribute this software and
9cc36ccd1SDavid Schultz its documentation for any purpose and without fee is hereby
10cc36ccd1SDavid Schultz granted, provided that the above copyright notice appear in all
11cc36ccd1SDavid Schultz copies and that both that the copyright notice and this
12cc36ccd1SDavid Schultz permission notice and warranty disclaimer appear in supporting
13cc36ccd1SDavid Schultz documentation, and that the name of Lucent or any of its entities
14cc36ccd1SDavid Schultz not be used in advertising or publicity pertaining to
15cc36ccd1SDavid Schultz distribution of the software without specific, written prior
16cc36ccd1SDavid Schultz permission.
17cc36ccd1SDavid Schultz
18cc36ccd1SDavid Schultz LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
19cc36ccd1SDavid Schultz INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
20cc36ccd1SDavid Schultz IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
21cc36ccd1SDavid Schultz SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
22cc36ccd1SDavid Schultz WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
23cc36ccd1SDavid Schultz IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
24cc36ccd1SDavid Schultz ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
25cc36ccd1SDavid Schultz THIS SOFTWARE.
26cc36ccd1SDavid Schultz
27cc36ccd1SDavid Schultz ****************************************************************/
28cc36ccd1SDavid Schultz
29c88250a5SDavid Schultz /* Please send bug reports to David M. Gay (dmg at acm dot org,
30c88250a5SDavid Schultz * with " at " changed at "@" and " dot " changed to "."). */
31cc36ccd1SDavid Schultz
32cc36ccd1SDavid Schultz #include "gdtoaimp.h"
33cc36ccd1SDavid Schultz
34cc36ccd1SDavid Schultz void
35cc36ccd1SDavid Schultz #ifdef KR_headers
ULtod(L,bits,exp,k)36cc36ccd1SDavid Schultz ULtod(L, bits, exp, k) ULong *L; ULong *bits; Long exp; int k;
37cc36ccd1SDavid Schultz #else
38cc36ccd1SDavid Schultz ULtod(ULong *L, ULong *bits, Long exp, int k)
39cc36ccd1SDavid Schultz #endif
40cc36ccd1SDavid Schultz {
41cc36ccd1SDavid Schultz switch(k & STRTOG_Retmask) {
42cc36ccd1SDavid Schultz case STRTOG_NoNumber:
43cc36ccd1SDavid Schultz case STRTOG_Zero:
44cc36ccd1SDavid Schultz L[0] = L[1] = 0;
45cc36ccd1SDavid Schultz break;
46cc36ccd1SDavid Schultz
47cc36ccd1SDavid Schultz case STRTOG_Denormal:
48cc36ccd1SDavid Schultz L[_1] = bits[0];
49cc36ccd1SDavid Schultz L[_0] = bits[1];
50cc36ccd1SDavid Schultz break;
51cc36ccd1SDavid Schultz
52cc36ccd1SDavid Schultz case STRTOG_Normal:
53cc36ccd1SDavid Schultz case STRTOG_NaNbits:
54cc36ccd1SDavid Schultz L[_1] = bits[0];
55cc36ccd1SDavid Schultz L[_0] = (bits[1] & ~0x100000) | ((exp + 0x3ff + 52) << 20);
56cc36ccd1SDavid Schultz break;
57cc36ccd1SDavid Schultz
58cc36ccd1SDavid Schultz case STRTOG_Infinite:
59cc36ccd1SDavid Schultz L[_0] = 0x7ff00000;
60cc36ccd1SDavid Schultz L[_1] = 0;
61cc36ccd1SDavid Schultz break;
62cc36ccd1SDavid Schultz
63cc36ccd1SDavid Schultz case STRTOG_NaN:
64c88250a5SDavid Schultz L[0] = d_QNAN0;
65c88250a5SDavid Schultz L[1] = d_QNAN1;
66cc36ccd1SDavid Schultz }
67cc36ccd1SDavid Schultz if (k & STRTOG_Neg)
68cc36ccd1SDavid Schultz L[_0] |= 0x80000000L;
69cc36ccd1SDavid Schultz }
70cc36ccd1SDavid Schultz
71cc36ccd1SDavid Schultz int
72cc36ccd1SDavid Schultz #ifdef KR_headers
strtord_l(s,sp,rounding,d,locale)73*3c87aa1dSDavid Chisnall strtord_l(s, sp, rounding, d, locale) CONST char *s; char **sp; int rounding;
74*3c87aa1dSDavid Chisnall double *d; locale_t locale;
75cc36ccd1SDavid Schultz #else
76*3c87aa1dSDavid Chisnall strtord_l(CONST char *s, char **sp, int rounding, double *d, locale_t locale)
77cc36ccd1SDavid Schultz #endif
78cc36ccd1SDavid Schultz {
79cc36ccd1SDavid Schultz static FPI fpi0 = { 53, 1-1023-53+1, 2046-1023-53+1, 1, SI };
80cc36ccd1SDavid Schultz FPI *fpi, fpi1;
81cc36ccd1SDavid Schultz ULong bits[2];
82cc36ccd1SDavid Schultz Long exp;
83cc36ccd1SDavid Schultz int k;
84cc36ccd1SDavid Schultz
85cc36ccd1SDavid Schultz fpi = &fpi0;
86cc36ccd1SDavid Schultz if (rounding != FPI_Round_near) {
87cc36ccd1SDavid Schultz fpi1 = fpi0;
88cc36ccd1SDavid Schultz fpi1.rounding = rounding;
89cc36ccd1SDavid Schultz fpi = &fpi1;
90cc36ccd1SDavid Schultz }
91*3c87aa1dSDavid Chisnall k = strtodg_l(s, sp, fpi, &exp, bits, locale);
92cc36ccd1SDavid Schultz ULtod((ULong*)d, bits, exp, k);
93cc36ccd1SDavid Schultz return k;
94cc36ccd1SDavid Schultz }
95*3c87aa1dSDavid Chisnall
96