Gop*_*opi 2 java math android exception
看过Double.java的源代码和一些常量就好
/**
* Constant for the Not-a-Number (NaN) value of the {@code double} type.
*/
public static final double NaN = 0.0 / 0.0;
/**
* Constant for the positive infinity value of the {@code double} type.
*/
public static final double POSITIVE_INFINITY = 1.0 / 0.0;
/**
* Constant for the negative infinity value of the {@code double} type.
*/
public static final double NEGATIVE_INFINITY = -1.0 / 0.0;
Run Code Online (Sandbox Code Playgroud)
但我想知道它为什么不抛出ArithmeticException(除以零)?
我试过了
public static final int VALUE = 0/0;
Run Code Online (Sandbox Code Playgroud)
现在它正在抛出异常,但是当我说
public static final double VALUE = 0d/0d;
Run Code Online (Sandbox Code Playgroud)
它没有抛出异常......
什么是魔法Double以及它为什么不抛出异常?
| 归档时间: |
|
| 查看次数: |
1464 次 |
| 最近记录: |