****************************************************************/
-/* Please send bug reports to
- David M. Gay
- dmg@acm.org
- */
+/* Please send bug reports to David M. Gay (dmg at acm dot org,
+ * with " at " changed at "@" and " dot " changed to "."). */
#include "gdtoaimp.h"
{
Bigint *b;
CONST unsigned char *decpt, *s0, *s, *s1;
- int esign, havedig, irv, k, n, nbits, up;
+ int esign, havedig, irv, k, n, nbits, up, zret;
ULong L, lostbits, *x;
Long e, e1;
#ifdef USE_LOCALE
- char decimalpoint = *localeconv()->decimal_point;
+ unsigned char decimalpoint = *localeconv()->decimal_point;
#else
#define decimalpoint '.'
#endif
s0 += havedig;
s = s0;
decpt = 0;
+ zret = 0;
+ e = 0;
if (!hexdig[*s]) {
- if (*s == decimalpoint) {
- decpt = ++s;
- if (!hexdig[*s])
- goto ret0;
- }
- else {
- ret0:
- *sp = (char*)s;
- return havedig ? STRTOG_Zero : STRTOG_NoNumber;
- }
+ zret = 1;
+ if (*s != decimalpoint)
+ goto pcheck;
+ decpt = ++s;
+ if (!hexdig[*s])
+ goto pcheck;
while(*s == '0')
s++;
+ if (hexdig[*s])
+ zret = 0;
havedig = 1;
- if (!hexdig[*s])
- goto ret0;
s0 = s;
}
while(hexdig[*s])
while(hexdig[*s])
s++;
}
- e = 0;
if (decpt)
e = -(((Long)(s-decpt)) << 2);
+ pcheck:
s1 = s;
switch(*s) {
case 'p':
e += e1;
}
*sp = (char*)s;
+ if (zret)
+ return havedig ? STRTOG_Zero : STRTOG_NoNumber;
n = s1 - s0 - 1;
for(k = 0; n > 7; n >>= 1)
k++;
if (e > fpi->emax) {
ovfl:
Bfree(b);
+ *bp = 0;
return STRTOG_Infinite | STRTOG_Overflow | STRTOG_Inexhi;
}
irv = STRTOG_Normal;
if (n >= nbits) {
switch (fpi->rounding) {
case FPI_Round_near:
- if (n == nbits && n < 2 || any_on(b,n-1))
+ if (n == nbits && (n < 2 || any_on(b,n-1)))
goto one_bit;
break;
case FPI_Round_up:
}
}
Bfree(b);
+ *bp = 0;
return STRTOG_Zero | STRTOG_Inexlo | STRTOG_Underflow;
}
k = n - 1;
k = b->wds;
b = increment(b);
x = b->x;
- if (b->wds > k
+ if (irv == STRTOG_Denormal) {
+ if (nbits == fpi->nbits - 1
+ && x[nbits >> kshift] & 1 << (nbits & kmask))
+ irv = STRTOG_Normal;
+ }
+ else if (b->wds > k
|| (n = nbits & kmask) !=0
&& hi0bits(x[k-1]) < 32-n) {
rshift(b,1);
if (++e > fpi->emax)
goto ovfl;
}
- else if (irv == STRTOG_Denormal) {
- k = nbits - 1;
- if (x[k >> kshift] & 1 << (k & kmask))
- irv = STRTOG_Normal;
- }
irv |= STRTOG_Inexhi;
}
else