changed the way reals are printed.
authorMark Linton <linton@ucbvax.Berkeley.EDU>
Wed, 17 Feb 1982 16:31:40 +0000 (08:31 -0800)
committerMark Linton <linton@ucbvax.Berkeley.EDU>
Wed, 17 Feb 1982 16:31:40 +0000 (08:31 -0800)
SCCS-vsn: usr.bin/pascal/pdx/sym/printval.c 1.4

usr/src/usr.bin/pascal/pdx/sym/printval.c

index 34ef207..37ee1b3 100644 (file)
@@ -1,6 +1,6 @@
 /* Copyright (c) 1982 Regents of the University of California */
 
 /* Copyright (c) 1982 Regents of the University of California */
 
-static char sccsid[] = "@(#)printval.c 1.3 %G%";
+static char sccsid[] = "@(#)printval.c 1.4 %G%";
 
 /*
  * Print out the value at the top of the stack using the given type.
 
 /*
  * Print out the value at the top of the stack using the given type.
@@ -21,6 +21,7 @@ SYM *s;
     SYM *t;
     ADDRESS a;
     int len;
     SYM *t;
     ADDRESS a;
     int len;
+    double r;
 
     if (s->class == REF) {
        s = s->type;
 
     if (s->class == REF) {
        s = s->type;
@@ -48,7 +49,7 @@ SYM *s;
 
        case RANGE:
            if (s == t_real) {
 
        case RANGE:
            if (s == t_real) {
-               printf("%g", pop(double));
+               printreal(pop(double));
            } else if (s == t_char) {
                printf("'%c'", pop(char));
            } else if (s == t_boolean) {
            } else if (s == t_char) {
                printf("'%c'", pop(char));
            } else if (s == t_boolean) {
@@ -188,3 +189,28 @@ SYM *a;
     sp = newsp;
     printf(")");
 }
     sp = newsp;
     printf(")");
 }
+
+/*
+ * Print out the value of a real number.
+ * Pascal notation is somewhat different that what one gets
+ * from "%g" in printf.
+ */
+
+LOCAL printreal(r)
+double r;
+{
+    extern char *index();
+    char *p, buf[256];
+
+    sprintf(buf, "%g", r);
+    if (buf[0] == '.') {
+       printf("0%s", buf);
+    } else if (buf[0] == '-' && buf[1] == '.') {
+       printf("-0%s", &buf[1]);
+    } else {
+       printf("%s", buf);
+    }
+    if (index(buf, '.') == NIL) {
+       printf(".0");
+    }
+}