]>
Commit | Line | Data |
---|---|---|
9385eb3d A |
1 | /**************************************************************** |
2 | ||
3 | The author of this software is David M. Gay. | |
4 | ||
5 | Copyright (C) 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 | ||
3d9156a7 A |
29 | /* Please send bug reports to David M. Gay (dmg at acm dot org, |
30 | * with " at " changed at "@" and " dot " changed to "."). */ | |
9385eb3d A |
31 | |
32 | #include "gdtoaimp.h" | |
33 | ||
34 | static void | |
35 | #ifdef KR_headers | |
36 | L_shift(x, x1, i) ULong *x; ULong *x1; int i; | |
37 | #else | |
38 | L_shift(ULong *x, ULong *x1, int i) | |
39 | #endif | |
40 | { | |
41 | int j; | |
42 | ||
43 | i = 8 - i; | |
44 | i <<= 2; | |
45 | j = ULbits - i; | |
46 | do { | |
47 | *x |= x[1] << j; | |
48 | x[1] >>= i; | |
49 | } while(++x < x1); | |
50 | } | |
51 | ||
52 | int | |
53 | #ifdef KR_headers | |
54 | hexnan(sp, fpi, x0) | |
55 | CONST char **sp; FPI *fpi; ULong *x0; | |
56 | #else | |
57 | hexnan( CONST char **sp, FPI *fpi, ULong *x0) | |
58 | #endif | |
59 | { | |
60 | ULong c, h, *x, *x1, *xe; | |
61 | CONST char *s; | |
62 | int havedig, hd0, i, nbits; | |
63 | ||
64 | if (!hexdig['0']) | |
65 | hexdig_init_D2A(); | |
66 | nbits = fpi->nbits; | |
67 | x = x0 + (nbits >> kshift); | |
68 | if (nbits & kmask) | |
69 | x++; | |
70 | *--x = 0; | |
71 | x1 = xe = x; | |
72 | havedig = hd0 = i = 0; | |
73 | s = *sp; | |
74 | while(c = *(CONST unsigned char*)++s) { | |
75 | if (!(h = hexdig[c])) { | |
76 | if (c <= ' ') { | |
77 | if (hd0 < havedig) { | |
78 | if (x < x1 && i < 8) | |
79 | L_shift(x, x1, i); | |
80 | if (x <= x0) { | |
81 | i = 8; | |
82 | continue; | |
83 | } | |
84 | hd0 = havedig; | |
85 | *--x = 0; | |
86 | x1 = x; | |
87 | i = 0; | |
88 | } | |
89 | continue; | |
90 | } | |
91 | if (/*(*/ c == ')' && havedig) { | |
92 | *sp = s + 1; | |
93 | break; | |
94 | } | |
95 | return STRTOG_NaN; | |
96 | } | |
97 | havedig++; | |
98 | if (++i > 8) { | |
99 | if (x <= x0) | |
100 | continue; | |
101 | i = 1; | |
102 | *--x = 0; | |
103 | } | |
104 | *x = (*x << 4) | h & 0xf; | |
105 | } | |
106 | if (!havedig) | |
107 | return STRTOG_NaN; | |
108 | if (x < x1 && i < 8) | |
109 | L_shift(x, x1, i); | |
110 | if (x > x0) { | |
111 | x1 = x0; | |
112 | do *x1++ = *x++; | |
113 | while(x <= xe); | |
114 | do *x1++ = 0; | |
115 | while(x1 <= xe); | |
116 | } | |
117 | else { | |
118 | /* truncate high-order word if necessary */ | |
119 | if ( (i = nbits & (ULbits-1)) !=0) | |
120 | *xe &= ((ULong)0xffffffff) >> (ULbits - i); | |
121 | } | |
122 | for(x1 = xe;; --x1) { | |
123 | if (*x1 != 0) | |
124 | break; | |
125 | if (x1 == x0) { | |
126 | *x1 = 1; | |
127 | break; | |
128 | } | |
129 | } | |
130 | return STRTOG_NaNbits; | |
131 | } |