为什么整数在Java中代表NaN?

编程入门 行业动态 更新时间:2024-10-23 17:34:16
本文介绍了为什么整数在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?

本文发布于:2023-11-25 02:45:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1628008.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:整数   代表   Java   NaN

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!