NaN comparisons - Call For Anecdotes

Terry Reedy tjreedy at udel.edu
Wed Jul 9 00:57:03 EDT 2014


On 7/8/2014 8:10 PM, Steven D'Aprano wrote:

> There's no force of law that requires Python to enforce reflexivity on
> values where reflexivity does not apply,

There are laws of logic that make the lack of reflexivity obnoxious when 
putting objects in collections. Python evaded the problem, at least for 
some builtins, by contradicting itself and treating nans as equal to 
themselves in the context of collections.

In 2.x, 'in' was defined in terms of ==, but
 >>> nan=float('nan')
 >>> nl = [nan]
 >>> nan in nl
True
even though nan != the only member of nl.

In 3.x, 'in' was redefined to include 'is' as well as '=='.

-- 
Terry Jan Reedy




More information about the Python-list mailing list