[Python-ideas] math.inf and math.nan constants
Nick Coghlan
ncoghlan at gmail.com
Fri Jan 9 13:34:46 CET 2015
On 9 January 2015 at 21:58, Alexander Heger <python at 2sn.net> wrote:
> here another odd issue related to NaN arithmetics:
> (2)
>>>> x = (nan,)
>>>> x is x
> True
>>>> x == x
> True
>
> ... hmm ... apparently the comparison uses ID before using == ? for
> tuple elements?
> I understand why they all give the results they do, however, I think
> the second comparison in (2) should give False
There's an inherent conflict between the mathematical notion of NaN
and the software engineering notion of object identity. For containers
in Python, it's the latter that prevails, in order to preserve the
invariant that "x is y" implies "x in (y,)" for arbitrary containers
and objects, even if x and y happen to be distinct references to the
exact same NaN object.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-ideas
mailing list