为什么double.NaN不等于自己? [英] Why is double.NaN not equal to itself?

查看:312
本文介绍了为什么double.NaN不等于自己?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以解释这样对我?在C#double.NaN不等于double.NaN

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 >= 0; // huh2 = false
bool huh3 = double.NaN <= 0; // huh3 = false

我可以比作double.NaN什么恒定的,并得到真正的?

What constant can I compare to a double.NaN and get true?

推荐答案

如果你是好奇,这就是 Double.IsNaN 是这样的:

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

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

时髦的,是吧?

Funky, huh?

这篇关于为什么double.NaN不等于自己?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆