• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /****************************************************************
2 
3 The author of this software is David M. Gay.
4 
5 Copyright (C) 1998, 2000 by Lucent Technologies
6 All Rights Reserved
7 
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
16 permission.
17 
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
25 THIS SOFTWARE.
26 
27 ****************************************************************/
28 
29 /* Please send bug reports to David M. Gay (dmg at acm dot org,
30  * with " at " changed at "@" and " dot " changed to ".").	*/
31 
32 #include "gdtoaimp.h"
33 
34  void
35 #ifdef KR_headers
ULtod(L,bits,exp,k)36 ULtod(L, bits, exp, k) ULong *L; ULong *bits; Long exp; int k;
37 #else
38 ULtod(ULong *L, ULong *bits, Long exp, int k)
39 #endif
40 {
41 	switch(k & STRTOG_Retmask) {
42 	  case STRTOG_NoNumber:
43 	  case STRTOG_Zero:
44 		L[0] = L[1] = 0;
45 		break;
46 
47 	  case STRTOG_Denormal:
48 		L[_1] = bits[0];
49 		L[_0] = bits[1];
50 		break;
51 
52 	  case STRTOG_Normal:
53 	  case STRTOG_NaNbits:
54 		L[_1] = bits[0];
55 		L[_0] = (bits[1] & ~0x100000) | ((exp + 0x3ff + 52) << 20);
56 		break;
57 
58 	  case STRTOG_Infinite:
59 		L[_0] = 0x7ff00000;
60 		L[_1] = 0;
61 		break;
62 
63 	  case STRTOG_NaN:
64 		L[0] = d_QNAN0;
65 		L[1] = d_QNAN1;
66 	  }
67 	if (k & STRTOG_Neg)
68 		L[_0] |= 0x80000000L;
69 	}
70 
71  int
72 #ifdef KR_headers
strtord_l(s,sp,rounding,d,locale)73 strtord_l(s, sp, rounding, d, locale) CONST char *s; char **sp; int rounding;
74 double *d; locale_t locale;
75 #else
76 strtord_l(CONST char *s, char **sp, int rounding, double *d, locale_t locale)
77 #endif
78 {
79 	static FPI fpi0 = { 53, 1-1023-53+1, 2046-1023-53+1, 1, SI };
80 	FPI *fpi, fpi1;
81 	ULong bits[2];
82 	Long exp;
83 	int k;
84 
85 	fpi = &fpi0;
86 	if (rounding != FPI_Round_near) {
87 		fpi1 = fpi0;
88 		fpi1.rounding = rounding;
89 		fpi = &fpi1;
90 		}
91 	k = strtodg_l(s, sp, fpi, &exp, bits, locale);
92 	ULtod((ULong*)d, bits, exp, k);
93 	return k;
94 	}
95 
96