[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Exponent sign printing with ~E
- To: CL-CLeanup@Sail.stanford.edu, Cassels@STONY-BROOK.SCRC.Symbolics.COM
- Subject: Exponent sign printing with ~E
- From: Robert A. Cassels <Cassels@STONY-BROOK.SCRC.Symbolics.COM>
- Date: Tue, 13 Sep 88 15:11 EDT
- In-reply-to: <870703-173352-132@Xerox>
Issue: ~E-EXPONENT-SIGN
References: CLtL pp. 366, 393
Category: CLARIFICATION
Edit history: Bob Cassels, 13 Sep 88
Related issues: <none>
Problem description:
The result of (format nil "~E" 1.0) is specified in a contradictory way.
The ambiguity is whether a plus sign should be printed in front of
the exponent.
The top of page 393 says, "Next, either a plus or a minus sign is
printed, followed by e digits ... [decimal exponent]"
Later on page 393 we see, "If all of w, d, and e are omitted, then the
effect is ... [like prin1].
Page 366 [presumably where prin1 is defined] doesn't explicitly say that
the plus sign is omitted from the exponent, but all the examples (and
usual practice) indicate that.
So the posssibilities are:
A. "1.0e+0"
B. "1.0e0"
The first reference implies that A is correct, the third reference
implies that B is correct. The second reference implies that A and B
are the same.
Proposal (~E-EXPONENT-SIGN:FORCE-SIGN):
Change the wording on page 393 to:
"If all of w, d, and e are omitted, then the effect is to print the
value using ordinary free-format exponential-notation output; PRIN1 uses
a similar format for any non-zero number whose magnitude is less than
10**-3 or greater than or equal to 10**7. The only difference is that
the ~E directive always prints a plus or minus sign in front of the
exponent, while PRIN1 omits the plus sign if the exponent is
non-negative."
Test Case:
(format nil "~E" 1.0) => "1.0e+0"
Rationale:
This proposal makes ~E self-consistent. That is more important than
making ~E consistent with PRIN1.
Current practice:
Symbolics Common Lisp, Ibuki Lisp, and VAX Lisp all print the plus
sign as in the test case above. Apollo DOMAIN Common Lisp (version
2.10) produces "1.0", which is simply wrong.
Adoption Cost:
Minimal changes to one printing routine for non-conforming
implementations. (No change to the three implementations mentioned
above.)
Cost of non-adoption:
Minor confusion and possible incompatibility among implementations.
Benefits:
Less confusion, more compatibility.
Conversion Cost:
Minimal. It is doubtful that any user programs depend on this
obscure distinction.
Esthetics:
A matter of opinion.
Discussion:
Fortran ~E format requires a sign before the exponent, since the exponent
mark character may be dropped. Since Common Lisp ~E always prints
the exponent marker, the exponent sign may be dropped in the case
that it would be a plus sign.