[New-bugs-announce] [issue7660] Two float('nan') are not equal

Jean-Michel Fauth report at bugs.python.org
Fri Jan 8 20:09:20 CET 2010


New submission from Jean-Michel Fauth <wxjmfauth at gmail.com>:

I did not find any report about this.

Windows 7, Python 2.6.4

>>> float('inf') == float('inf')
True
>>> float('-inf') == float('-inf')
True
>>> float('-inf') == float('inf')
False
>>> float('-inf') != float('inf')
True
>>> float('nan') == float('nan')
False
>>> float('nan') != float('nan')
True
>>> 

I'm not an expert on that field, I wonder if the following is
not related to a sign bit missmatch, see also Python 3.1.1 below.

>>> copysign(1, float('inf'))
1.0
>>> copysign(1, float('-inf'))
-1.0
>>> copysign(1, float('nan'))
-1.0
>>> copysign(1, float('-nan'))
-1.0
>>> 

Windows 7, Python 3.1.1

>>> float('inf') == float('inf')
True
>>> float('-inf') == float('-inf')
True
>>> float('-inf') == float('inf')
False
>>> float('-inf') != float('inf')
True
>>> float('nan') == float('nan')
False
>>> float('nan') != float('nan')
True
>>> 

Same behaviour as with Python 2.6.4

>>> copysign(1, float('inf'))
1.0
>>> copysign(1, float('-inf'))
-1.0
>>> copysign(1, float('nan'))
-1.0
>>> copysign(1, float('-nan'))  <<<<<<<<<<<<<<<<<<<
1.0
>>> 

Different behaviour from Python 2.6.4

----------
components: None
messages: 97432
nosy: jmfauth
severity: normal
status: open
title: Two float('nan') are not equal
type: behavior
versions: Python 2.6

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue7660>
_______________________________________


More information about the New-bugs-announce mailing list