Double.isNaN() 如何工作?
sun jdk 实现看起来像这样:
return v != v;
谁能解释一下它是如何工作的?
The sun jdk implementation looks like this:
return v != v;
Can anyone explain how that works?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
NaN 值不等于任何值(如果等式的一侧为 NaN,则等式为 false),因此 NaN != NaN。显然,每个正常的双精度数都等于自身
NaN values are not equal to anything (if one side of an equality is NaN, the equality is false), so NaN != NaN. Obviously every normal double does equal itself
nan 是唯一不等于自身的双精度值。因此,检查 v!=v 只会为 NaN 生成 True。
以下是 Java 规范 的内容说:
A nan is the only double that is not equal to itself. Thus, checking v!=v will only produce True for NaN.
Here is what the Java spec has to say: