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

后端 未结 5 1314
太阳男子
太阳男子 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 10:03

    To get a float type temporary variable to actually hold a single precision value, it must have been loaded from a float variable in memory. The compiler is generally allowed to represent single-precision values with more precision than required, and tends to do so while the value is in a register. When it spills back to memory the extra precision is lost.

提交回复
热议问题