Division by zero: int vs. float

后端 未结 6 429
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-16 05:18

Dividing an int by zero, will throw an exception, but a float won\'t - at least in Java. Why does a float have additional NaN info, while an int type doesn\'t?

6条回答
  •  时光说笑
    2021-01-16 05:46

    Java reflects the way most CPUs are implemented. Integer divide by zero causes an interrupt on x86/x64 and Floating point divide by zero results in Infinity, Negative infinity or NaN. Note: with floating point you can also divide by negative zero. :P

提交回复
热议问题