本文介绍了为什么整数在Java中代表NaN?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
double a = 0.0; double b = 0.0; double c = a / b;
结果是 Double.NaN ,但当我尝试相同的整数时,它会产生一个 ArithmeticException 。那么为什么没有一个 Integer.NaN ?
解决方案答案与Java无关。无穷大或未定义的数字不是整数集的一部分,因此它们从 Integer 中排除,而浮点类型则表示实数和复数,因此要处理这些 NaN 已经包含浮点类型。
When I write something like
double a = 0.0; double b = 0.0; double c = a/b;The result is Double.NaN, but when I try the same for integers, it produces an ArithmeticException. So, why isn't there a Integer.NaN?
解决方案The answer has very little to do with Java. Infinity or undefined numbers are not a part of the integer set, so they are excluded from Integer, whereas floating point types represent real numbers as well as complex numbers, so to deal with these, NaN has been included with floating point types.
更多推荐
为什么整数在Java中代表NaN?
发布评论