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

c#, floating-point, overflow

Solution

Because the `1` is way too small to make a dent in the `float.MaxValue` value.

Anything less than 1e32 will fall below the precision of the float, so it's in effect the same as adding a zero.

Edit:

ulrichb showed that a value of 1e23 does actually affect float.MaxValue, which has to mean that you are not comparing floats at all, but doubles. The compiler converts all values to doubles before adding and comparing.

Problem

I wonder if you could explain the Overflow in floating-point types. ``` float.MaxValue == float.MaxValue + 1 // returns true ```

Original source