Comparing Double.NaN with itself

后端 未结 4 1294
迷失自我
迷失自我 2021-02-06 21:58

I am stuck trying to find out why these two operations return different values:

  1. Double.NaN == Double.NaN returns false
  2. Do
4条回答
  •  太阳男子
    2021-02-06 22:26

    At the very bottom of the remarks section of Double.Equals, you will find:

    If two Double.NaN values are tested for equality by calling the Equals method, the method returns true. However, if two NaN values are tested for equality by using the equality operator, the operator returns false. When you want to determine whether the value of a Double is not a number (NaN), an alternative is to call the IsNaN method.

提交回复
热议问题