j: Next unread message
k: Previous unread message
j a: Jump to all threads
j l: Jump to MailingList overview
2017-09-21 3:53 GMT+02:00 Steven D'Aprano firstname.lastname@example.org:
float.fromhex(s) if s.startswith('0x') else float(s)
My vote is now -1 on extending the Python syntax to add hexadecimal floating literals.
While I was first in favor of extending the Python syntax, I changed my mind. Float constants written in hexadecimal is a (very?) rare use case, and there is already float.fromhex() available.
A new syntax is something more to learn when you learn Python. Is it worth it? I don't think so. Very few people need to write hexadecimal constants in their code.
For hardcore developers loving bytes, struct.unpack() is also available for your pleasure.
Moreover, there is also slowly a trend to compute floating point numbers in decimal since it's easier to understand and debug (by humans ;-)). We already have a fast "decimal" module in Python 3.