Adrian Aichner wrote:
APA> FAIL: Assertion failed: (string= (format "%e"
100) "1.000000e+02")
Stephen> Oops, oh, yeah, that too.
Stephen> Funny how those Windows bugs never get fixed. There was
Stephen, I looked into this a bit.
These tests all fail because of a three digit exponent being printed
by MS printf.
Using cygwin I get two-digit exponents printed instead of three.
However, reading
http://www.opengroup.org/onlinepubs/007904975/functions/printf.html
seems to suggest that three digit exponents are not in violation with
the following excerpt:
e, E
The double argument shall be converted in the style "[-]d.ddde±dd",
where there is one digit before the radix character (which is non-zero
if the argument is non-zero) and the number of digits after it is
equal to the precision; if the precision is missing, it shall be taken
as 6; if the precision is zero and no '#' flag is present, no radix
character shall appear. The low-order digit shall be rounded in an
implementation-defined manner. The E conversion specifier shall
produce a number with 'E' instead of 'e' introducing the exponent. The
exponent shall always contain at least two digits. If the value is
zero, the exponent shall be zero.
A double argument representing an infinity or NaN shall be converted
in the style of an f or F conversion specifier.
That's almost identical to the ANSI C specification, but not quite:
e,E A double argument representing a (finite) floating- |
point number is converted in the style [-]d.ddde±dd,
where there is one digit (which is nonzero if the
argument is nonzero) before the decimal-point
character and the number of digits after it is equal
to the precision; if the precision is missing, it is
taken as 6; if the precision is zero and the # flag
is not specified, no decimal-point character
appears. The value is rounded to the appropriate
number of digits. The E conversion specifier
produces a number with E instead of e introducing
the exponent. The exponent always contains at least
two digits, AND ONLY AS MANY MORE DIGITS AS
NECESSARY TO REPRESENT THE EXPONENT. If the value
is zero, the exponent is zero.
A double argument representing an infinity or NaN is
converted in the style of an f or F conversion
specifier.
[Emphasis mine.]
IOW, the MSVC printf() may be compatible with Unix98, but it isn't
compatible with ANSI C.
However, this is the specification of the C *printf functions; nothing
requires that the elisp "format" function behaves similarly. FWIW, the
lispref Info file just says:
`%e'
Replace the specification with the exponential notation for a
floating point number (e.g. `7.85200e+03').
It doesn't include any claims of compatibility with C's *printf
family; or even a mention of them, for that matter.
Given that we don't appear to be under any obligation to mimic the
ANSI C semantics, I can't see any harm in defining the semantics of
the %e specifier in such a way that it can be implemented using MSVC's
sprintf().
--
Glynn Clements <glynn.clements(a)virgin.net>