"/a" is not "/a" ?
dickinsm at gmail.com
Sun Mar 8 18:39:56 CET 2009
On Mar 7, 2:14 pm, Christian Heimes <li... at cheimes.de> wrote:
> Steven D'Aprano wrote:
> > Yes. Floating point NANs are required to compare unequal to all floats,
> > including themselves. It's part of the IEEE standard.
> As far as I remember that's not correct. It's just the way C has
> interpreted the standard and Python inherited the behavior. But you may
> proof me wrong on that.
Steven's statement sounds about right to me: IEEE 754
(the current 2008 version of the standard, which supersedes
the original 1985 version that I think Robert Kern is
referring to) says that every NaN compares *unordered*
to anything else (including itself). A compliant language is
required to supply twenty-two(!) comparison operations, including
a 'compareQuietEqual' operation with compareQuietEqual(NaN, x)
being False, and also a 'compareSignalingEqual' operation, such
that compareSignalingEqual(NaN, x) causes an 'invalid operation
exception'. See sections 5.6.1 and 5.11 of the standard for
Throughout the above, 'NaN' means quiet NaN. A comparison
involving a signaling NaN should always cause an invalid operation
exception. I don't think Python really supports signaling NaNs
in any meaningful way.
I wonder what happens if you create an sNaN using
struct.unpack(suitable_byte_string) and then try
to do arithmetic on it in Python...
More information about the Python-list