[Python-ideas] math.inf and math.nan constants

Chris Barker - NOAA Federal chris.barker at noaa.gov
Mon Jan 12 06:23:40 CET 2015


> But it's not a singleton, not even in the class of NaNs.  It's a named
> constant, like zero or pi.

Right, it's a particular value of a float -- more that that, it's a
bunch if values, so even less a singleton than pi, even.

>> math.isnan(x)
>
> In Python we spell that "isinstance", not "is".

Except that nan is not a type.

In way, it's like how there are two bit patterns for the value 0.0 in
floats (-0.0 and 0.0). But in that case, -0.0 == 0.0 is True. Whereas
NaN == NaN is false. hence the need for math.isnan.

Honestly, I wasn't really thinking it would be a good idea, but it did
seem like it could make it a pseudo-singleton, and be a, as Chris A.
puts it, "cute" way to express it.

Not cute enough to create a weird exception to an otherwise clearly
defined operator, however.

-CHB


More information about the Python-ideas mailing list