/** * A constant holding the positive infinity of type * {@code float}. It is equal to the value returned by * {@code Float.intBitsToFloat(0x7f800000)}. */ publicstaticfinalfloat POSITIVE_INFINITY = 1.0f / 0.0f;
/** * A constant holding the negative infinity of type * {@code float}. It is equal to the value returned by * {@code Float.intBitsToFloat(0xff800000)}. */ publicstaticfinalfloat NEGATIVE_INFINITY = -1.0f / 0.0f;
/** * A constant holding a Not-a-Number (NaN) value of type * {@code float}. It is equivalent to the value returned by * {@code Float.intBitsToFloat(0x7fc00000)}. */ publicstaticfinalfloat NaN = 0.0f / 0.0f;
/** * A constant holding the positive infinity of type * {@code double}. It is equal to the value returned by * {@code Double.longBitsToDouble(0x7ff0000000000000L)}. */ publicstaticfinaldouble POSITIVE_INFINITY = 1.0 / 0.0;
/** * A constant holding the negative infinity of type * {@code double}. It is equal to the value returned by * {@code Double.longBitsToDouble(0xfff0000000000000L)}. */ publicstaticfinaldouble NEGATIVE_INFINITY = -1.0 / 0.0;
/** * A constant holding a Not-a-Number (NaN) value of type * {@code double}. It is equivalent to the value returned by * {@code Double.longBitsToDouble(0x7ff8000000000000L)}. */ publicstaticfinaldouble NaN = 0.0d / 0.0;
NaN
NaN是Not a Number的缩写,表示未定义或者不可表示的值,NaN有一个特性,那就是它与任何数都不相等,包括它自己。判断一个数是不是NaN,只能使用Float或者Double的isNaN()方法,那么这个方法是怎么判断的呢?我们看一看(查看的是Float版,Double除了参数类型都一样,下面二者没有区别的部分都直接使用Float的内容来说明):
1 2 3 4 5 6 7 8 9 10 11
/** * Returns {@code true} if the specified number is a * Not-a-Number (NaN) value, {@code false} otherwise. * * @param v the value to be tested. * @return {@code true} if the argument is NaN; * {@code false} otherwise. */ publicstaticbooleanisNaN(float v){ return (v != v); }