public static void main(String[] arg0) {
double c = 1.0 / 0.0;
double d = 2.0 / 0.0;
//true
System.out.println(c == d);
//true
System.out.println(c == Double.POSITIVE_INFINITY);
//true
System.out
.println(Double.POSITIVE_INFINITY == Double.POSITIVE_INFINITY);
System.out.println("===================");
double e = -1.0 / 0.0;
double f = -2.0 / 0.0;
//true
System.out.println(e == f);
//true
System.out
.println(Double.c== Double.NEGATIVE_INFINITY);
System.out.println("===================");
double h = 0.0 / 0.0;
//false
System.out.println(Float.NaN == Float.NaN);
//false
System.out.println(h == Float.NaN);
}
0、无穷大、无穷小和非数都是浮点型,且默认字面量都是double类型
1、所有的无穷大都是相等的:1.0/0.0==2.0/0.0==Float.POSITIVE_INFINITY==Double.POSITIVE_INFINITY
2、所有的无穷小都是相等的:-1.0/0.0==-2.0/0.0==Float.NEGATIVE_INFINITY==Doulbe.NEGATIVE_INFINITY
3、所有的非数都是不相等的:Float.NaN!=Double.NaN!=0.0/0.0