[Python-ideas] math.inf and math.nan constants
Devin Jeanpierre
jeanpierreda at gmail.com
Mon Jan 12 05:44:18 CET 2015
On Sun, Jan 11, 2015 at 3:55 PM, Chris Barker <chris.barker at noaa.gov> wrote:
> Though it would be pretty cool if you could override "is" to make:
>
> x is math.nan
>
> be:
>
> math.isnan(x)
>
> and maybe the same thing for any arbitrary floats that may have nan values:
>
> x is y
>
> becomes:
>
> True if math.isnan(x) and math.isnan(y) else (id(x) == id(y))
>
> (or something like that...)
>
> Is that even possible to override is that way?
Not in Python. Anyway, a huge motivation for "is" is to know that if x
is y, then foo(x) is exactly equivalent to foo(y). That would no
longer be the if all nans were "identical", since struct.pack can give
different values for different nans.
-- Devin
More information about the Python-ideas
mailing list