[issue42210] float.hex discards sign from -nan

Sree report at bugs.python.org
Mon Nov 2 12:14:37 EST 2020


Sree <sree314 at gmail.com> added the comment:

Thanks, all. I just wanted to know if this was a deliberate decision or an oversight. It also took me a while to realize it washex, and not fromhex.

That allows the current behaviour to be easily worked around in Python code, and a backwards compatible optional parameter to hex() might allow -nan in the future without breaking existing software.

Surprisingly, the standard does allow this [but this may not have been the intent] -- (Section 6.2) "Recognize that format conversions,
including conversions between supported formats and external representations as character sequences,
might be unable to deliver the same NaN." The conversion to character sequences text is key since I'm using a test harness written in Python that writes out and reads back text files containing float data.

Section 6.3 in the standard also adds more details on when the sign bit in NaNs is relevant.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42210>
_______________________________________


More information about the Python-bugs-list mailing list