This commit is contained in:
ceriel 1988-08-03 16:15:48 +00:00
parent caf948e80e
commit 3e66a45a0d

View file

@ -2,7 +2,7 @@
#ifndef NOFLOAT #ifndef NOFLOAT
extern char *ecvt(); extern char *ecvt();
#define NDIGINEXP 2 #define NDIGINEXP(exp) (((exp) >= 100 || (exp) <= -100) ? 3 : 2)
char * char *
gcvt(value, ndigit, buf) gcvt(value, ndigit, buf)
@ -18,7 +18,7 @@ gcvt(value, ndigit, buf)
s2 = buf; s2 = buf;
if (sign) *s2++ = '-'; if (sign) *s2++ = '-';
for (i = ndigit - 1; i > 0 && s1[i] == '0'; i--) ndigit--; for (i = ndigit - 1; i > 0 && s1[i] == '0'; i--) ndigit--;
if (dp - ndigit > NDIGINEXP + 2 || dp < -NDIGINEXP - 1) { if (dp - ndigit > NDIGINEXP(dp) + 2 || dp < -NDIGINEXP(dp) - 1) {
/* Use E format, otherwise we need too many '0''s */ /* Use E format, otherwise we need too many '0''s */
dp--; dp--;
*s2++ = *s1++; *s2++ = *s1++;
@ -30,8 +30,9 @@ gcvt(value, ndigit, buf)
dp = -dp; dp = -dp;
} }
else *s2++ = '+'; else *s2++ = '+';
s2 += NDIGINEXP; s2 += NDIGINEXP(dp);
for (i = NDIGINEXP; i > 0; i--) { *s2 = 0;
for (i = NDIGINEXP(dp); i > 0; i--) {
*--s2 = dp % 10 + '0'; *--s2 = dp % 10 + '0';
dp /= 10; dp /= 10;
} }