L
luser- -droog
I can't seem to figure out how to get printf to display a
real number with at least one fraction digit (even if it's
zero) but no unnecessary zeros. I've resorted to this:
void RScvs(state *st, object r, object s) { int n;
n = snprintf(STR(s), s.u.c.n+1, "%g", r.u.r);
if (strchr(STR(s), '.')==NULL) { strncat(STR(s),".0", s.u.c.n-n); n
+=2; }
if (n > s.u.c.n) error(st,rangecheck); if (n < s.u.c.n) s.u.c.n =
n; push(s); }
But I'm not really happy with it.
typedef struct composite {
address a;
size off;
size n;
} composite;
typedef struct object {
byte tag;
flags flags;
/* x86 puts two bytes of padding here
so the real (double) is 32-bit aligned
I don't know what to use it for.
*/
union {
boolean b;
integer i;
unsigned u;
real r; /* dominates the union */
composite c;
} u;
} object;
real number with at least one fraction digit (even if it's
zero) but no unnecessary zeros. I've resorted to this:
void RScvs(state *st, object r, object s) { int n;
n = snprintf(STR(s), s.u.c.n+1, "%g", r.u.r);
if (strchr(STR(s), '.')==NULL) { strncat(STR(s),".0", s.u.c.n-n); n
+=2; }
if (n > s.u.c.n) error(st,rangecheck); if (n < s.u.c.n) s.u.c.n =
n; push(s); }
But I'm not really happy with it.
typedef struct composite {
address a;
size off;
size n;
} composite;
typedef struct object {
byte tag;
flags flags;
/* x86 puts two bytes of padding here
so the real (double) is 32-bit aligned
I don't know what to use it for.
*/
union {
boolean b;
integer i;
unsigned u;
real r; /* dominates the union */
composite c;
} u;
} object;