浅谈C#中的Infinity和NaN

作者:袖梨 2022-06-25

C#中double和float类型有两个特殊值:

Infinity(无穷大):5.0 / 0.0 = Infinity

NaN(not a number):0.0 / 0.0 = NaN

计算表达式 0.0 / 0.0 = NaN,

NaN和Infinity可以在表达式中使用:

10 + Infinity = Infinity

10 + NaN = NaN

Infinity * 0 = 0

NaN * 0 = NaN

相关文章

精彩推荐