The failure of the `x == x` test for signaling NaNs may be a non-issue in 
practice, for a couple of reasons; one is that signaling NaNs are *supposed* to 
raise when you do almost anything at all with them. The other is that, unlike a 
quiet NaN, it's hard to imagine how anyone would ever get a signaling NaN by 
accident.

CPython doesn't support signaling NaNs for `float`, essentially because C has 
no explicit support for signaling NaNs. You can create (e.g., via the `struct` 
module) NaNs whose bit pattern should in theory make them signaling NaNs, but 
at least on platforms I've worked with, they don't behave any differently from 
quiet NaNs. Essentially, in CPython, all NaNs are quiet, which is the reason 
that the Decimal module refuses to convert signaling NaNs to `float`. (I've no 
idea what happens in Jython or IronPython here.)

Just about the only observable aspect of IEEE 754 signaling NaNs that I can 
detect on my laptop is that of signaling NaNs being converted to the 
corresponding quiet NaNs in arithmetic operations:

    >>> snan = struct.unpack('<d', b'\1\2\3\0\0\0\xf0\xff')[0]
    >>> struct.pack('<d', snan)
    b'\x01\x02\x03\x00\x00\x00\xf0\xff'
    >>> struct.pack('<d', snan + 3.5)
    b'\x01\x02\x03\x00\x00\x00\xf8\xff'

Note the single bit change in bit 51 (the msb of the significand field). On 
other platforms, it's possible that doing the above will cause an FPE-induced 
crash instead.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/6KHDH7SE24Y3DOGIU2D5YZT4WT3V2KYG/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to