gethex.c (179918) | gethex.c (182709) |
---|---|
1/**************************************************************** 2 3The author of this software is David M. Gay. 4 5Copyright (C) 1998 by Lucent Technologies 6All Rights Reserved 7 8Permission to use, copy, modify, and distribute this software and --- 31 unchanged lines hidden (view full) --- 40gethex(sp, fpi, exp, bp, sign) 41 CONST char **sp; FPI *fpi; Long *exp; Bigint **bp; int sign; 42#else 43gethex( CONST char **sp, FPI *fpi, Long *exp, Bigint **bp, int sign) 44#endif 45{ 46 Bigint *b; 47 CONST unsigned char *decpt, *s0, *s, *s1; | 1/**************************************************************** 2 3The author of this software is David M. Gay. 4 5Copyright (C) 1998 by Lucent Technologies 6All Rights Reserved 7 8Permission to use, copy, modify, and distribute this software and --- 31 unchanged lines hidden (view full) --- 40gethex(sp, fpi, exp, bp, sign) 41 CONST char **sp; FPI *fpi; Long *exp; Bigint **bp; int sign; 42#else 43gethex( CONST char **sp, FPI *fpi, Long *exp, Bigint **bp, int sign) 44#endif 45{ 46 Bigint *b; 47 CONST unsigned char *decpt, *s0, *s, *s1; |
48 int esign, havedig, irv, k, n, nbits, up, zret; | 48 int big, esign, havedig, irv, j, k, n, n0, nbits, up, zret; |
49 ULong L, lostbits, *x; 50 Long e, e1; 51#ifdef USE_LOCALE 52 unsigned char decimalpoint = *localeconv()->decimal_point; 53#else 54#define decimalpoint '.' 55#endif 56 57 if (!hexdig['0']) 58 hexdig_init_D2A(); | 49 ULong L, lostbits, *x; 50 Long e, e1; 51#ifdef USE_LOCALE 52 unsigned char decimalpoint = *localeconv()->decimal_point; 53#else 54#define decimalpoint '.' 55#endif 56 57 if (!hexdig['0']) 58 hexdig_init_D2A(); |
59 *bp = 0; |
|
59 havedig = 0; 60 s0 = *(CONST unsigned char **)sp + 2; 61 while(s0[havedig] == '0') 62 havedig++; 63 s0 += havedig; 64 s = s0; 65 decpt = 0; 66 zret = 0; --- 18 unchanged lines hidden (view full) --- 85 decpt = ++s; 86 while(hexdig[*s]) 87 s++; 88 } 89 if (decpt) 90 e = -(((Long)(s-decpt)) << 2); 91 pcheck: 92 s1 = s; | 60 havedig = 0; 61 s0 = *(CONST unsigned char **)sp + 2; 62 while(s0[havedig] == '0') 63 havedig++; 64 s0 += havedig; 65 s = s0; 66 decpt = 0; 67 zret = 0; --- 18 unchanged lines hidden (view full) --- 86 decpt = ++s; 87 while(hexdig[*s]) 88 s++; 89 } 90 if (decpt) 91 e = -(((Long)(s-decpt)) << 2); 92 pcheck: 93 s1 = s; |
94 big = esign = 0; |
|
93 switch(*s) { 94 case 'p': 95 case 'P': | 95 switch(*s) { 96 case 'p': 97 case 'P': |
96 esign = 0; | |
97 switch(*++s) { 98 case '-': 99 esign = 1; 100 /* no break */ 101 case '+': 102 s++; 103 } 104 if ((n = hexdig[*s]) == 0 || n > 0x19) { 105 s = s1; 106 break; 107 } 108 e1 = n - 0x10; | 98 switch(*++s) { 99 case '-': 100 esign = 1; 101 /* no break */ 102 case '+': 103 s++; 104 } 105 if ((n = hexdig[*s]) == 0 || n > 0x19) { 106 s = s1; 107 break; 108 } 109 e1 = n - 0x10; |
109 while((n = hexdig[*++s]) !=0 && n <= 0x19) | 110 while((n = hexdig[*++s]) !=0 && n <= 0x19) { 111 if (e1 & 0xf8000000) 112 big = 1; |
110 e1 = 10*e1 + n - 0x10; | 113 e1 = 10*e1 + n - 0x10; |
114 } |
|
111 if (esign) 112 e1 = -e1; 113 e += e1; 114 } 115 *sp = (char*)s; | 115 if (esign) 116 e1 = -e1; 117 e += e1; 118 } 119 *sp = (char*)s; |
116 if (zret) { 117 if (!havedig) 118 *sp = s0 - 1; | 120 if (!havedig) 121 *sp = s0 - 1; 122 if (zret) |
119 return STRTOG_Zero; | 123 return STRTOG_Zero; |
124 if (big) { 125 if (esign) { 126 switch(fpi->rounding) { 127 case FPI_Round_up: 128 if (sign) 129 break; 130 goto ret_tiny; 131 case FPI_Round_down: 132 if (!sign) 133 break; 134 goto ret_tiny; 135 } 136 goto retz; 137 ret_tiny: 138 b = Balloc(0); 139 b->wds = 1; 140 b->x[0] = 1; 141 goto dret; 142 } 143 switch(fpi->rounding) { 144 case FPI_Round_near: 145 goto ovfl1; 146 case FPI_Round_up: 147 if (!sign) 148 goto ovfl1; 149 goto ret_big; 150 case FPI_Round_down: 151 if (sign) 152 goto ovfl1; 153 goto ret_big; 154 } 155 ret_big: 156 nbits = fpi->nbits; 157 n0 = n = nbits >> kshift; 158 if (nbits & kmask) 159 ++n; 160 for(j = n, k = 0; j >>= 1; ++k); 161 *bp = b = Balloc(k); 162 b->wds = n; 163 for(j = 0; j < n0; ++j) 164 b->x[j] = ALL_ON; 165 if (n > n0) 166 b->x[j] = ULbits >> (ULbits - (nbits & kmask)); 167 *exp = fpi->emin; 168 return STRTOG_Normal | STRTOG_Inexlo; |
|
120 } 121 n = s1 - s0 - 1; 122 for(k = 0; n > 7; n >>= 1) 123 k++; 124 b = Balloc(k); 125 x = b->x; 126 n = 0; 127 L = 0; --- 16 unchanged lines hidden (view full) --- 144 x = b->x; 145 if (n > nbits) { 146 n -= nbits; 147 if (any_on(b,n)) { 148 lostbits = 1; 149 k = n - 1; 150 if (x[k>>kshift] & 1 << (k & kmask)) { 151 lostbits = 2; | 169 } 170 n = s1 - s0 - 1; 171 for(k = 0; n > 7; n >>= 1) 172 k++; 173 b = Balloc(k); 174 x = b->x; 175 n = 0; 176 L = 0; --- 16 unchanged lines hidden (view full) --- 193 x = b->x; 194 if (n > nbits) { 195 n -= nbits; 196 if (any_on(b,n)) { 197 lostbits = 1; 198 k = n - 1; 199 if (x[k>>kshift] & 1 << (k & kmask)) { 200 lostbits = 2; |
152 if (k > 1 && any_on(b,k-1)) | 201 if (k > 0 && any_on(b,k)) |
153 lostbits = 3; 154 } 155 } 156 rshift(b, n); 157 e += n; 158 } 159 else if (n < nbits) { 160 n = nbits - n; 161 b = lshift(b, n); 162 e -= n; 163 x = b->x; 164 } 165 if (e > fpi->emax) { 166 ovfl: 167 Bfree(b); | 202 lostbits = 3; 203 } 204 } 205 rshift(b, n); 206 e += n; 207 } 208 else if (n < nbits) { 209 n = nbits - n; 210 b = lshift(b, n); 211 e -= n; 212 x = b->x; 213 } 214 if (e > fpi->emax) { 215 ovfl: 216 Bfree(b); |
168 *bp = 0; | 217 ovfl1: 218#ifndef NO_ERRNO 219 errno = ERANGE; 220#endif |
169 return STRTOG_Infinite | STRTOG_Overflow | STRTOG_Inexhi; 170 } 171 irv = STRTOG_Normal; 172 if (e < fpi->emin) { 173 irv = STRTOG_Denormal; 174 n = fpi->emin - e; 175 if (n >= nbits) { 176 switch (fpi->rounding) { 177 case FPI_Round_near: 178 if (n == nbits && (n < 2 || any_on(b,n-1))) 179 goto one_bit; 180 break; 181 case FPI_Round_up: 182 if (!sign) 183 goto one_bit; 184 break; 185 case FPI_Round_down: 186 if (sign) { 187 one_bit: | 221 return STRTOG_Infinite | STRTOG_Overflow | STRTOG_Inexhi; 222 } 223 irv = STRTOG_Normal; 224 if (e < fpi->emin) { 225 irv = STRTOG_Denormal; 226 n = fpi->emin - e; 227 if (n >= nbits) { 228 switch (fpi->rounding) { 229 case FPI_Round_near: 230 if (n == nbits && (n < 2 || any_on(b,n-1))) 231 goto one_bit; 232 break; 233 case FPI_Round_up: 234 if (!sign) 235 goto one_bit; 236 break; 237 case FPI_Round_down: 238 if (sign) { 239 one_bit: |
188 *exp = fpi->emin; | |
189 x[0] = b->wds = 1; | 240 x[0] = b->wds = 1; |
241 dret: |
|
190 *bp = b; | 242 *bp = b; |
243 *exp = fpi->emin; 244#ifndef NO_ERRNO 245 errno = ERANGE; 246#endif |
|
191 return STRTOG_Denormal | STRTOG_Inexhi 192 | STRTOG_Underflow; 193 } 194 } 195 Bfree(b); | 247 return STRTOG_Denormal | STRTOG_Inexhi 248 | STRTOG_Underflow; 249 } 250 } 251 Bfree(b); |
196 *bp = 0; | 252 retz: 253#ifndef NO_ERRNO 254 errno = ERANGE; 255#endif |
197 return STRTOG_Zero | STRTOG_Inexlo | STRTOG_Underflow; 198 } 199 k = n - 1; 200 if (lostbits) 201 lostbits = 1; 202 else if (k > 0) 203 lostbits = any_on(b,k); 204 if (x[k>>kshift] & 1 << (k & kmask)) --- 46 unchanged lines hidden --- | 256 return STRTOG_Zero | STRTOG_Inexlo | STRTOG_Underflow; 257 } 258 k = n - 1; 259 if (lostbits) 260 lostbits = 1; 261 else if (k > 0) 262 lostbits = any_on(b,k); 263 if (x[k>>kshift] & 1 << (k & kmask)) --- 46 unchanged lines hidden --- |