Double源代码笔记

1, MIN_NORMAL:最小的标准值(没看懂)。估计是数学概念方面的东西。

      MIN_VALUE:最小的非零常量。觉得这是用于计算用的。而且只是Double的这个容器的最小值。

 

2,

static public boolean isNaN(double v) {

	return (v != v);

    }
 

NaN表示这不是一个数字。通过这样判断,让我有很吃惊的感觉。google了一下。有这么一段解释

Floating-point operators produce no exceptions (§11). An operation that overflows produces a signed infinity, an operation that underflows produces a denormalized value or a signed zero, and an operation that has no mathematically definite result produces NaN. All numeric operations with NaN as an operand produce NaN as a result. As has already been described, NaN is unordered, so a numeric comparison operation involving one or two NaNs returns false and any != comparison involving NaN returns true, including x!=x when x is NaN.

NaN是unordered. 所以来说任何比较符都是false.

然后写了这么一段测试代码进行验证

/**

	 * 1>NaN:false

     *1<NaN:false

	 */

	@Test

	public void NanTest(){

		System.out.println("1>NaN:"+(1.0>Double.NaN));

		System.out.println("1<NaN:"+(1.0<Double.NaN));

	}

 

 

3 对精度要求高的计算,不要使用Double。而是使用BigDecimal,但是效率会比较低。

Double会出现一些错误,比较99999之类的。

你可能感兴趣的:(double)