float("nan") in set or as key

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sun May 29 14:46:54 EDT 2011


On Sun, 29 May 2011 20:05:07 +0200, Christian Heimes wrote:

> Am 29.05.2011 19:44, schrieb MRAB:
>> 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?
> 
> It can't be a singleton, because IEEE 754 specifies millions of millions
> of different NaN values. 

A million-millioneton then? *wink*


> There are positive and negative NaNs, 

I've never quite understood that. NANs are unordered, and therefore 
cannot be said to be larger than zero (positive) or less than zero 
(negative). So even if a NAN has the sign bit set, surely the right way 
to think about that is to treat the sign bit as part of the payload?

It seems to me that talking about signed NANs is inaccurate and adds 
confusion. NANs cause enough confusion as it is, without adding to it...

(I would expect the copysign function to honour the sign bit, so I 
suppose in that sense one might describe NANs as signed.)



-- 
Steven



More information about the Python-list mailing list