为什么整数在Java中代表NaN? [英] Why doesn't Integer represent NaN in Java?

查看:107
本文介绍了为什么整数在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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆