[Python-ideas] Hexadecimal floating literals
Victor Stinner
victor.stinner at gmail.com
Tue Sep 12 03:23:04 EDT 2017
2017-09-12 3:48 GMT+02:00 Steven D'Aprano <steve at pearwood.info>:
>> k = float("0x1.2492492492492p-3") # 1/7
>
> Why wouldn't you just write 1/7?
1/7 is irrational, so it's not easy to get the "exact value" for a
64-bit IEEE 754 double float.
I chose it because it's easy to write. Maybe math.pi is a better example :-)
>>> math.pi.hex()
'0x1.921fb54442d18p+1'
Victor
More information about the Python-ideas
mailing list