replace 10 by 10.0, so that the conversion is not done at runtime

This commit is contained in:
ceriel 1987-10-22 13:58:48 +00:00
parent 245397491a
commit b75744f0d4

View file

@ -26,8 +26,8 @@ cvt(value, ndigit, decpt, sign, ecvtflag)
int ndigit, *decpt, *sign; int ndigit, *decpt, *sign;
{ {
double intpart, fractpart; double intpart, fractpart;
static char buf[NDIGITS]; static char buf[NDIGITS+1];
char buf1[NDIGITS]; char buf1[NDIGITS+1];
register char *pe = buf1; register char *pe = buf1;
register char *pb; register char *pb;
int pointpos = 0; int pointpos = 0;
@ -47,7 +47,7 @@ cvt(value, ndigit, decpt, sign, ecvtflag)
do { /* get digits of integer part, low order digit do { /* get digits of integer part, low order digit
first first
*/ */
value = modf(intpart/10, &intpart); value = modf(intpart/10.0, &intpart);
/* compensate for rounding errors, because /* compensate for rounding errors, because
the conversion to "int" truncates the conversion to "int" truncates
*/ */
@ -56,7 +56,7 @@ cvt(value, ndigit, decpt, sign, ecvtflag)
pe = &buf1[0]; pe = &buf1[0];
while (pb < &buf1[NDIGITS]) *pe++ = *pb++; while (pb < &buf1[NDIGITS]) *pe++ = *pb++;
} }
*pe++ = (int)((value+.05) * 10) + '0'; *pe++ = (int)((value+.05) * 10.0) + '0';
pointpos++; pointpos++;
} while (intpart != 0); } while (intpart != 0);
pb = buf; pb = buf;
@ -66,7 +66,7 @@ cvt(value, ndigit, decpt, sign, ecvtflag)
pb = &buf[0]; pb = &buf[0];
if (value > 0) { if (value > 0) {
fractpart = value; fractpart = value;
while ((value = value*10) < 1) { while ((value = value*10.0) < 1) {
fractpart = value; fractpart = value;
pointpos--; pointpos--;
} }
@ -85,7 +85,7 @@ cvt(value, ndigit, decpt, sign, ecvtflag)
if (pe > &buf[NDIGITS]) pe = &buf[NDIGITS]; if (pe > &buf[NDIGITS]) pe = &buf[NDIGITS];
} }
while (pb <= pe) { while (pb <= pe) {
fractpart = modf(fractpart * 10, &value); fractpart = modf(fractpart * 10.0, &value);
*pb++ = (int)value + '0'; *pb++ = (int)value + '0';
} }
pb = pe; pb = pe;