<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Sep 8, 2017 at 12:05 PM, Victor Stinner <span dir="ltr"><<a href="mailto:victor.stinner@gmail.com" target="_blank">victor.stinner@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">2017-09-07 23:57 GMT-07:00 Serhiy Storchaka <<a href="mailto:storchaka@gmail.com">storchaka@gmail.com</a>>:<br>
> The support of hexadecimal floating literals (like 0xC.68p+2) is included in<br>
> just released C++17 standard. Seems this becomes a mainstream.<br>
<br>
</span>Floating literal using base 2 (or base 2^n, like hexadecimal, 2^4) is<br>
the only way to get exact values in a portable way. So yeah, we need<br>
it. We already have float.hex() since Python 2.6.<br>
<span class=""><br>
> In Python float.hex() returns hexadecimal string representation. Is it a<br>
> time to add more support of hexadecimal floating literals? Accept them in<br>
> float constructor and in Python parser? And maybe add support of hexadecimal<br>
> formatting ('%x' and '{:x}')?<br>
<br>
</span>I dislike "%x" % float, since "%x" is a very old format from C printf<br>
and I expect it to only work for integers. For example, bytes.hex()<br>
exists (since Python 3.5) but b'%x' % b'hello' doesn't work.<br>
<br>
Since format() is a "new" way to format strings, and each type is free<br>
to implement its own formatters, I kind of like the idea of support<br>
float.hex() here.<br>
<br>
Do we need a short PEP, since it changes the Python grammar? It may be<br>
nice to describe the exact grammar for float literals.<span class="HOEnZb"></span><br clear="all"></blockquote></div></div><div class="gmail_extra"><br></div><div class="gmail_extra">Yes, this needs a PEP.</div><div class="gmail_extra"><br></div><div class="gmail_extra">-- <br><div class="gmail_signature" data-smartmail="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</div></div>