Proposal: === and !=== operators

Steven D'Aprano steve+comp.lang.python at pearwood.info
Thu Jul 10 03:10:24 CEST 2014


On Wed, 09 Jul 2014 13:05:22 -0500, Tim Chase wrote:

> If you want to compare things in a NaN-aware way, you can either spell
> it out explicitly:
> 
>   if x == y or (math.isnan(x) and math.isnan(y)):
>     do_stuff()

But do we really want any arbitrary NAN to compare equal-ish with every 
other NAN? There are 9007199254740990 distinct NANs (slightly less than 
0.05% of the total number of floats). 

Much to my disappointment, frexp doesn't return the payload and exponent 
of NANs, at least not on Linux:

py> math.frexp(NAN)
(nan, 0)

so it can't be used to distinguish different NANs.


-- 
Steven



More information about the Python-list mailing list