[Python-ideas] Hexadecimal floating literals

Neil Schemenauer nas-python-ideas at arctrix.com
Mon Sep 11 20:26:16 EDT 2017

On 2017-09-12, Victor Stinner wrote:
> Instead of modifying the Python grammar, the alternative is to enhance
> float(str) to support it:
> k = float("0x1.2492492492492p-3") # 1/7

Making it a different function from float() would avoid backwards
compatibility issues. I.e. float() no longer returns errors on some


    from math import hexfloat
    k = hexfloat("0x1.2492492492492p-3")

I still think a literal syntax has merits.  The above cannot be
optimized by the compiler as it doesn't know what hexfloat() refers
to.  That in turn destroys constant folding peephole stuff that uses
the literal.

More information about the Python-ideas mailing list