flt_chk(e);
}
-#define NDIGITS 128
+#define NDIG 18
static char *
-flt_ecvt(e, ndigit, decpt, sign)
+flt_ecvt(e, decpt, sign)
register flt_arith *e;
- int ndigit, *decpt, *sign;
+ int *decpt, *sign;
{
/* Like ecvt(), but for extended precision */
- static char buf[NDIGITS+1];
+ static char buf[NDIG+1];
register char *p = buf;
register char *pe;
register int findex = 0;
- if (ndigit < 0) ndigit = 0;
- if (ndigit > NDIGITS) ndigit = NDIGITS;
- pe = &buf[ndigit];
+ pe = &buf[NDIG];
buf[0] = '\0';
*sign = 0;
}
}
*pe = '\0';
+ while (--pe > buf && *pe == '0') *pe = '\0';
}
return buf;
}
char *buf;
{
-#define NDIG 19
int sign, dp;
register int i;
register char *s1;
e1 = *e;
flt_status = 0;
- s1 = flt_ecvt(&e1,NDIG,&dp,&sign);
+ s1 = flt_ecvt(&e1,&dp,&sign);
if (sign)
*s++ = '-';
*s++ = *s1++;
*s++ = '.';
for (i = NDIG-1; i > 0; i--) {
if (*s1) *s++ = *s1++;
- else *s++ = '0';
+ else {
+ if (i == NDIG-1) *s++ = '0';
+ break;
+ }
}
if (e->m1 | e->m2) {
--dp ;
int oper;
char *result;
} tests[] = {
- { "1.0", 0, 0, "1.000000000000000000" },
- { "-1.0", 0, 0, "-1.000000000000000000" },
- { "0.0", 0, 0, "0.000000000000000000" },
- { "1.234567", 0, 0, "1.234567000000000000" },
- { "1.234567", 0, 'D', "1.000000000000000000" },
- { "1.234567", 0, 'R', "2.345670000000000000e-1" },
- { "32768", "32768", '+', "6.553600000000000000e+4" },
- { "32768", "32767", '-', "1.000000000000000000" },
- { "32768", "32768", '*', "1.073741824000000000e+9" },
- { "32768", "32768", '/', "1.000000000000000000" },
- { "1.234567e20", "-1.234567e20", '+', "0.000000000000000000" },
+ { "1.0", 0, 0, "1.0" },
+ { "-1.0", 0, 0, "-1.0" },
+ { "0.0", 0, 0, "0.0" },
+ { "1.234567", 0, 0, "1.234567" },
+ { "1.234567", 0, 'D', "1.0" },
+ { "1.234567", 0, 'R', "2.34567e-1" },
+ { "32768", "32768", '+', "6.5536e+4" },
+ { "32768", "32767", '-', "1.0" },
+ { "32768", "32768", '*', "1.073741824e+9" },
+ { "32768", "32768", '/', "1.0" },
+ { "1.234567e20", "-1.234567e20", '+', "0.0" },
+ { "1e100", "1e100", '+', "2.0e+100" },
+ { "1e110", "10", '*', "1.0e+111" },
+ { "0.5e100", "0.5e100", '*', "2.5e+199" },
{ 0, 0, 0, 0}
};
if (! strcmp(buf, p->result)) return 1;
- printf("Test number %d failed\n", testno);
+ printf("Test number %d failed: result = %s, should be %s\n", testno, buf, p->result);
return 0;
}