%a format
John Lenton
john at grulic.org.ar
Tue Sep 7 23:28:03 CEST 2004
On Tue, Sep 07, 2004 at 12:21:49PM -0700, Erik Max Francis wrote:
> Tor Iver Wilhelmsen wrote:
>
> > John Lenton <john at grulic.org.ar> writes:
> >
> > > Is there any reason python's printf-style formatting is missing the
> > > (C99) '%a' specifier?
> >
> > Because it's not very well known or used? A google for "C printf
> > format string" gave lots of resources, none of which had %a.
>
> It's not C99, anyway; my copy of C99 makes no mention of it (the only
> mention of %a is associated with gmtime.
hmm! weird. From printf(3):
a,A (C99; not in SUSv2) For a conversion, the double
argument is converted to hexadecimal notation (using the
letters abcdef) in the style [‐]0xh.hhhhp±d; for A
conversion the prefix 0X, the letters ABCDEF, and the
exponent separator P is used. There is one hexadecimal
digit before the decimal point, and the number of digits
after it is equal to the precision. The default
precision suffices for an exact representation of the
value if an exact representation in base 2 exists and
otherwise is sufficiently large to distinguish values of
type double. The digit before the decimal point is
unspecified for non‐normalized numbers, and nonzero but
otherwise unspecified for normalized numbers.
and looking at ISO/IEC 9899:1999 (E), it's on page 278, §7.19.6.1:
a,A
A double argument representing a floating-point number is
converted in the style [-]0xh.hhhh p±d, where there is one
hexadecimal digit (which is nonzero if the argument is a
normalized floating-point number and is otherwise unspecified)
before the decimal-point character235) and the number of
hexadecimal digits after it is equal to the precision; if the
precision is missing and FLT_RADIX is a power of 2, then the
precision is sufficient for an exact representation of the value;
if the precision is missing and FLT_RADIX is not a power of 2,
then the precision is sufficient to distinguish236) values of type
double, except that trailing zeros may be omitted; if the
precision is zero and the # flag is not specified, no decimalpoint
character appears. The letters abcdef are used for a conversion
and the letters ABCDEF for A conversion. The A conversion
specifier produces a number with X and P instead of x and p. The
exponent always contains at least one digit, and only as many more
digits as necessary to represent the decimal exponent of 2. 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.
--
John Lenton (john at grulic.org.ar) -- Random fortune:
It seems intuitively obvious to me, which means that it might be wrong.
-- Chris Torek
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 196 bytes
Desc: Digital signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20040907/3915e804/attachment.pgp>
More information about the Python-list
mailing list