Why [float.MaxValue == float.MaxValue + 1] does return true?

后端 未结 5 1307
太阳男子
太阳男子 2020-12-06 09:07

I wonder if you could explain the Overflow in floating-point types.

float.MaxValue == float.MaxValue + 1 // returns true
5条回答
  •  长情又很酷
    2020-12-06 09:41

    The problem here is floating point precision. float.MaxValue corresponds to 3.40282e+038f. But a float has much less precision that, in fact, there are only 7 digits of precision.

    Anything beyond that precision is "filled with zeros", and adding 1 to that high number will not change it.

提交回复
热议问题