[SciPy-user] Puzzling NAN semantics

Gregory Novak novak at ucolick.org
Tue Mar 21 19:19:35 CST 2006


I'm confused by the semantics of nan:

  def the_test(a,b):
      print a, " less than ", b, ":", a<b
      print a, " equals ", b, ":", a==b
      print a, " greater than ", b, ":",a>b

  In [85]: the_test(5,6)
  5  less than  6 : True
  5  equals  6 : False
  5  greater than  6 : False

  In [86]: the_test(5,5)
  5  less than  5 : False
  5  equals  5 : True
  5  greater than  5 : False

So far so good

  In [87]: the_test(5,nan)
  5  less than  nan : False
  5  equals  nan : True
  5  greater than  nan : False

This doens't seem desirable: any number is equal to nan?

  In [88]: the_test(nan,nan)
  nan  less than  nan : False
  nan  equals  nan : True
  nan  greater than  nan : False

I believe that the IEEE standard says that nan is _not_ equal to itself

  In [89]: the_test(array([5,5]), array([5,nan]))
  [5 5]  less than  [ 5. nan] : [False False]
  [5 5]  equals  [ 5. nan] : [True False]
  [5 5]  greater than  [ 5. nan] : [False False]

  In [90]: the_test(array([nan,nan]), array([5,nan]))
  [nan nan]  less than  [ 5. nan] : [False False]
  [nan nan]  equals  [ 5. nan] : [False False]
  [nan nan]  greater than  [ 5. nan] : [False False]

When nan appears inside arrays, the behavior is what I expected: nan
is not equal to, greater than, or less than anything, including
itself.

I'm using OS X 10.4.5, Python 2.3.5, IPython 0.6.15, scipy-core 0.9.5,
scipy 0.4.6, and Numeric 24.2

Should I consider this a bug?

Thanks,
Greg



More information about the SciPy-user mailing list