[Python-ideas] Hexadecimal floating literals

Victor Stinner victor.stinner at gmail.com
Tue Sep 12 03:24:39 EDT 2017


2017-09-12 1:27 GMT+02:00 Neil Schemenauer <neil at python.ca>:
>> 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
> inputs.

In that case, I suggest float.fromhex() to remain consistent the bytes example:

>>> b'123'.hex()
'313233'
>>> bytes.fromhex('313233')
b'123'

... Oh wait, it already exists...

 >>> float.fromhex('0x1.921fb54442d18p+1')
3.141592653589793

:-D

Victor


More information about the Python-ideas mailing list