本文介绍了为什么Double.NaN == Double.NaN返回false?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是在研究OCPJP的问题,我发现这个奇怪的代码:
$ b $ pre $ public static void main(String a []) {
System.out.println(Double.NaN == Double.NaN);
System.out.println(Double.NaN!= Double.NaN);
}

当我运行代码时,我得到了:

  false 
true

当我们比较两个看起来相同的东西时,输出如何 false ? NaN的意思是不是一个数字(NaN)意思是不是一个数字 。




$ b


I was just studying OCPJP questions and I found this strange code:

public static void main(String a[]) {
    System.out.println(Double.NaN==Double.NaN);
    System.out.println(Double.NaN!=Double.NaN);
}

When I ran the code, I got:

false
true

How is the output false when we're comparing two things that look the same as each other? What does NaN mean?

解决方案

NaN means "Not a Number".

Java Language Specification (JLS) Third Edition says:

这篇关于为什么Double.NaN == Double.NaN返回false?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 08:18