[Python-ideas] Hexadecimal floating literals

Guido van Rossum guido at python.org
Fri Sep 8 15:23:16 EDT 2017

On Fri, Sep 8, 2017 at 12:05 PM, Victor Stinner <victor.stinner at gmail.com>

> 2017-09-07 23:57 GMT-07:00 Serhiy Storchaka <storchaka at gmail.com>:
> > The support of hexadecimal floating literals (like 0xC.68p+2) is
> included in
> > just released C++17 standard. Seems this becomes a mainstream.
> Floating literal using base 2 (or base 2^n, like hexadecimal, 2^4) is
> the only way to get exact values in a portable way. So yeah, we need
> it. We already have float.hex() since Python 2.6.
> > In Python float.hex() returns hexadecimal string representation. Is it a
> > time to add more support of hexadecimal floating literals? Accept them in
> > float constructor and in Python parser? And maybe add support of
> hexadecimal
> > formatting ('%x' and '{:x}')?
> I dislike "%x" % float, since "%x" is a very old format from C printf
> and I expect it to only work for integers. For example, bytes.hex()
> exists (since Python 3.5) but b'%x' % b'hello' doesn't work.
> Since format() is a "new" way to format strings, and each type is free
> to implement its own formatters, I kind of like the idea of support
> float.hex() here.
> Do we need a short PEP, since it changes the Python grammar? It may be
> nice to describe the exact grammar for float literals.

Yes, this needs a PEP.

--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170908/7c418337/attachment.html>

More information about the Python-ideas mailing list