Int vs Double and divide by zero exception [duplicate]

泄露秘密 提交于 2019-12-01 06:51:01

Because that's how it's defined. Whereas with integers there are no special values for infinity and NaN, so the compiler throws an error if it can spot the problem at compile time.

Because of their mathematical background. Infinity is defined for floating point numbers but not for integers.

theoretically speaking division by zero should result in infinity, but the integer datatype has nothing to represent infinity. the double datatype does, so there is no need to throw an exception there.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!