[Python-ideas] Why is nan != nan?
Alexander Belopolsky
alexander.belopolsky at gmail.com
Thu Mar 25 19:06:47 CET 2010
> On Wed, Mar 24, 2010 at 7:31 PM, Mark Dickinson <dickinsm at gmail.com> wrote:
..
>> What if the two nans have different payloads or signs?
>
> They are still equal. Just as 0.0 and -0.0 are now.
>
Interestingly, Java departs from IEEE 754 on that last point as well:
"""
Note that in most cases, for two instances of class Double, d1 and d2,
the value of d1.equals(d2) is true if and only if
d1.doubleValue() == d2.doubleValue()
also has the value true. However, there are two exceptions:
If d1 and d2 both represent Double.NaN, then the equals method returns
true, even though Double.NaN==Double.NaN has the value false.
If d1 represents +0.0 while d2 represents -0.0, or vice versa, the
equal test has the value false, even though +0.0==-0.0 has the value
true. This allows hashtables to operate properly.
""" http://java.sun.com/j2se/1.3/docs/api/java/lang/Double.html
More information about the Python-ideas
mailing list