本文介绍了为什么C#允许浮点类型划分非零数字被零?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么C#允许:
1.0 / 0 // Infinity
和不允许:
1 / 0 // Division by constant zero [Compile time error]
在数学上,有积分和浮点之间的差异在被零除点数?
Mathematically, is there any differences between integral and floating-point numbers in dividing by zero?
推荐答案
据微软称,浮点运算溢出或除以零从未抛出异常由于浮点类型是基于IEEE 754,因此有代表无穷大,NaN(非数字)的规定。
According to Microsoft, "Floating-point arithmetic overflow or division by zero never throws an exception, because floating-point types are based on IEEE 754 and so have provisions for representing infinity and NaN (Not a Number)."
更多关于此的。
这篇关于为什么C#允许浮点类型划分非零数字被零?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!