NaN与Go中的NaN不同吗?

Can anyone explain why this happens? http://play.golang.org/p/QTaHpUm5P7

Apologies for not pasting the code here as well but I'm on mobile ATM.

I know I could use math.IsNaN() but I'm using the comparison operator for all my tests cases.

Generally, NaN is not considered equal to any number, including itself. That's because it represnts a number outside the range of representation.

Hence there's no guarantee that you don't have two different numbers outside the representation, such as 0 / 0 and the square root of -1.

In fact, many systems rely on this inequality to implement isNan() as something like:

define isNaN(x):
    return x != x

From the NaN Wikipedia page, IEEE 754 defines that:

  • −∞ = −∞,
  • +∞ = +∞ and
  • x ≠ NaN for any x, including NaN.

This is a duplicate of What is the rationale for all comparisons returning false for IEEE754 NaN values? - NaN never equals itself in IEE754, the linked answer explains why.