problem fixed: number of digits displayed and/or format was sometimes wrong
This commit is contained in:
parent
b26e580a74
commit
1726d23a44
|
@ -8,22 +8,23 @@ char *
|
||||||
gcvt(value, ndigit, buf)
|
gcvt(value, ndigit, buf)
|
||||||
double value;
|
double value;
|
||||||
char *buf;
|
char *buf;
|
||||||
register int ndigit;
|
int ndigit;
|
||||||
{
|
{
|
||||||
int sign, dp;
|
int sign, dp;
|
||||||
register char *s1, *s2;
|
register char *s1, *s2;
|
||||||
register int i;
|
register int i;
|
||||||
|
register int nndigit = ndigit;
|
||||||
|
|
||||||
s1 = ecvt(value, ndigit, &dp, &sign);
|
s1 = ecvt(value, ndigit, &dp, &sign);
|
||||||
s2 = buf;
|
s2 = buf;
|
||||||
if (sign) *s2++ = '-';
|
if (sign) *s2++ = '-';
|
||||||
for (i = ndigit - 1; i > 0 && s1[i] == '0'; i--) ndigit--;
|
for (i = nndigit - 1; i > 0 && s1[i] == '0'; i--) nndigit--;
|
||||||
if (dp - ndigit > NDIGINEXP(dp) + 2 || dp < -NDIGINEXP(dp) - 1) {
|
if (dp > ndigit || 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++;
|
||||||
*s2++ = '.';
|
*s2++ = '.';
|
||||||
while (--ndigit > 0) *s2++ = *s1++;
|
while (--nndigit > 0) *s2++ = *s1++;
|
||||||
*s2++ = 'e';
|
*s2++ = 'e';
|
||||||
if (dp < 0) {
|
if (dp < 0) {
|
||||||
*s2++ = '-';
|
*s2++ = '-';
|
||||||
|
@ -48,7 +49,7 @@ gcvt(value, ndigit, buf)
|
||||||
*s2++ = '0';
|
*s2++ = '0';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (i = 1; i <= ndigit; i++) {
|
for (i = 1; i <= nndigit; i++) {
|
||||||
*s2++ = *s1++;
|
*s2++ = *s1++;
|
||||||
if (i == dp) *s2++ = '.';
|
if (i == dp) *s2++ = '.';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue