[Python-ideas] Disallow orderring comparison to NaN

Mark Dickinson dickinsm at gmail.com
Sat Apr 30 10:13:46 CEST 2011


On Thu, Apr 28, 2011 at 5:12 PM, Alexander Belopolsky
<alexander.belopolsky at gmail.com> wrote:
> Furthermore, IEEE 754 specifies exactly what I propose:
>
> """
> IEEE 754 assigns values to all relational expressions involving NaN.
> In the syntax of C , the predicate x != y is True but all others, x <
> y , x <= y , x == y , x >= y and x > y, are False whenever x or y or
> both are NaN, and then all but x != y and x == y are INVALID
> operations too and must so signal.
> """
> -- Lecture Notes on the Status of IEEE Standard 754 for Binary
> Floating-Point Arithmetic by Prof. W. Kahan
> http://www.cs.berkeley.edu/~wkahan/ieee754status/ieee754.ps

Note that this text refers to the obsolete IEEE 754-1985, not the
current version of the standard.

IEEE 754 isn't really much help here:  the current version of the
standard specifies (in section 5.11: Details of comparison predicates)
*twenty-two* distinct comparison predicates.  That includes, for
example:

  'compareSignalingGreater'

which is a greater-than comparison that signals an invalid operation
exception on a comparison involving NaNs.  But it also includes:

  'compareQuietGreater'

which returns False for comparisons involving NaNs.  And IEEE 754 has
nothing to say about how the specified operations should be mapped to
language constructs---that's out of scope for the specification.  (It
does happen to list plain '>' as one of the names for
'compareSignalingGreater', but I don't think it's realistic to try to
read anything into that.)

I'm -0 on the proposal: I don't think there's enough of a real problem
here to justify the change.

Mark



More information about the Python-ideas mailing list