JAVA-数值计算中的特殊情况,NAN,Infinity

 最近在项目中遇到了double数据出现Infinity的情况;于是对数值计算中几种比较特殊的情况进行了实践:

	public static void main(String[] args) {
		
		// 非0number/0.0
		System.out.println((double)(5/0.0));
	
		// 0/0.0
		System.out.println((double)(0/0.0));
		
		// 0.0/0.0
		System.out.println((double)(0.0/0.0));
		
		// MAX_VALUE/MIN_VALUE
		System.out.println((double)(Double.MAX_VALUE/Double.MIN_VALUE));
		
		
		// 0/0
	    //System.out.println((double)(0/0));
		
		// 非0number/0
	   // System.out.println((double)(5/0));

	}

结果:

Infinity
NaN
NaN
Infinity

java.lang.ArithmeticException: / by zero

java.lang.ArithmeticException: / by zero


需要特别注意!!!

你可能感兴趣的:(遇到的BUG)