--- ray/src/cal/rcalc.c 2014/03/09 20:07:27 1.23 +++ ray/src/cal/rcalc.c 2014/05/10 01:48:14 1.25 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rcalc.c,v 1.23 2014/03/09 20:07:27 greg Exp $"; +static const char RCSid[] = "$Id: rcalc.c,v 1.25 2014/05/10 01:48:14 greg Exp $"; #endif /* * rcalc.c - record calculator program. @@ -801,10 +801,11 @@ struct field *f static void putrec(void) /* output a record */ { - char fmt[32]; + char fmt[32], typ[16]; int n; struct field *f; int adlast, adnext; + double dv, av; adlast = 0; for (f = outfmt; f != NULL; f = f->next) { @@ -835,13 +836,24 @@ putrec(void) /* output break; case T_NUM: n = f->type & F_WID; + dv = evalue(f->f.ne); + av = fabs(dv); + if (n <= 9) + strcpy(typ, "g"); + else + sprintf(typ, ".%de", n-5); + if (av < 1L<<31) { + long iv = (int)(av + .5); + if (iv && fabs(av-iv) <= av*1e-14) + strcpy(typ, ".0f"); + } if (adlast && adnext) - strcpy(fmt, "%g"); + sprintf(fmt, "%%%s", typ); else if (adlast) - sprintf(fmt, "%%-%dg", n); + sprintf(fmt, "%%-%d%s", n, typ); else - sprintf(fmt, "%%%dg", n); - printf(fmt, evalue(f->f.ne)); + sprintf(fmt, "%%%d%s", n, typ); + printf(fmt, dv); adlast = 1; break; }