Why is double.NaN not equal to itself?

后端 未结 11 1301
心在旅途
心在旅途 2020-11-27 17:42

Can someone explain this to me? In C# double.NaN is not equal to double.NaN

bool huh = double.NaN == double.NaN; // huh = false
bool huh2 = double.NaN >=          


        
11条回答
  •  星月不相逢
    2020-11-27 18:31

    If you are curious, this is what Double.IsNaN looks like:

    public static bool IsNaN(double d)
    {
        return (d != d);
    }
    

    Funky, huh?

提交回复
热议问题