1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27:
28:
29: 30:
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:
75: while((c = *(CONST unsigned char*)(s+1)) && c <= ' ')
76: ++s;
77: if (s[1] == '0' && (s[2] == 'x' || s[2] == 'X')
78: && *(CONST unsigned char*)(s+3) > ' ')
79: s += 2;
80: while((c = *(CONST unsigned char*)++s)) {
81: if (!(h = hexdig[c])) {
82: if (c <= ' ') {
83: if (hd0 < havedig) {
84: if (x < x1 && i < 8)
85: L_shift(x, x1, i);
86: if (x <= x0) {
87: i = 8;
88: continue;
89: }
90: hd0 = havedig;
91: *--x = 0;
92: x1 = x;
93: i = 0;
94: }
95: while(*(CONST unsigned char*)(s+1) <= ' ')
96: ++s;
97: if (s[1] == '0' && (s[2] == 'x' || s[2] == 'X')
98: && *(CONST unsigned char*)(s+3) > ' ')
99: s += 2;
100: continue;
101: }
102: if ( c == ')' && havedig) {
103: *sp = s + 1;
104: break;
105: }
106: #ifndef GDTOA_NON_PEDANTIC_NANCHECK
107: do {
108: if ( c == ')') {
109: *sp = s + 1;
110: break;
111: }
112: } while((c = *++s));
113: #endif
114: return STRTOG_NaN;
115: }
116: havedig++;
117: if (++i > 8) {
118: if (x <= x0)
119: continue;
120: i = 1;
121: *--x = 0;
122: }
123: *x = (*x << 4) | (h & 0xf);
124: }
125: if (!havedig)
126: return STRTOG_NaN;
127: if (x < x1 && i < 8)
128: L_shift(x, x1, i);
129: if (x > x0) {
130: x1 = x0;
131: do *x1++ = *x++;
132: while(x <= xe);
133: do *x1++ = 0;
134: while(x1 <= xe);
135: }
136: else {
137:
138: if ( (i = nbits & (ULbits-1)) !=0)
139: *xe &= ((ULong)0xffffffff) >> (ULbits - i);
140: }
141: for(x1 = xe;; --x1) {
142: if (*x1 != 0)
143: break;
144: if (x1 == x0) {
145: *x1 = 1;
146: break;
147: }
148: }
149: return STRTOG_NaNbits;
150: }