float("nan") in set or as key

Chris Angelico rosuav at gmail.com
Sun May 29 13:50:15 EDT 2011


On Mon, May 30, 2011 at 3:44 AM, MRAB <python at mrabarnett.plus.com> wrote:
> Would there be any advantage to making NaN a singleton? I'm thinking
> that it could make checking for it cheaper in the implementation of
> sets and dicts. Or making NaN unhashable?

Doesn't matter. It still wouldn't be equal to itself, even though it
'is' itself, which will greatly confuse anything that optimizes that
away. Numbers are well-behaved; NaN is not a number; NaN is not
well-behaved. It makes sense... in a way.

Chris Angelico



More information about the Python-list mailing list