ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cal/rcalc.c
(Generate patch)

Comparing ray/src/cal/rcalc.c (file contents):
Revision 1.23 by greg, Sun Mar 9 20:07:27 2014 UTC vs.
Revision 1.25 by greg, Sat May 10 01:48:14 2014 UTC

# Line 801 | Line 801 | struct field  *f
801   static void
802   putrec(void)                                /* output a record */
803   {
804 <        char  fmt[32];
804 >        char  fmt[32], typ[16];
805          int  n;
806          struct field  *f;
807          int  adlast, adnext;
808 +        double  dv, av;
809          
810          adlast = 0;
811          for (f = outfmt; f != NULL; f = f->next) {
# Line 835 | Line 836 | putrec(void)                                /* output
836                          break;
837                  case T_NUM:
838                          n = f->type & F_WID;
839 +                        dv = evalue(f->f.ne);
840 +                        av = fabs(dv);
841 +                        if (n <= 9)
842 +                                strcpy(typ, "g");
843 +                        else
844 +                                sprintf(typ, ".%de", n-5);
845 +                        if (av < 1L<<31) {
846 +                                long    iv = (int)(av + .5);
847 +                                if (iv && fabs(av-iv) <= av*1e-14)
848 +                                        strcpy(typ, ".0f");
849 +                        }
850                          if (adlast && adnext)
851 <                                strcpy(fmt, "%g");
851 >                                sprintf(fmt, "%%%s", typ);
852                          else if (adlast)
853 <                                sprintf(fmt, "%%-%dg", n);
853 >                                sprintf(fmt, "%%-%d%s", n, typ);
854                          else
855 <                                sprintf(fmt, "%%%dg", n);
856 <                        printf(fmt, evalue(f->f.ne));
855 >                                sprintf(fmt, "%%%d%s", n, typ);
856 >                        printf(fmt, dv);
857                          adlast = 1;
858                          break;
859                  }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines