Is “(float)integer == integer” guaranteed to be equal in C#?
问题 While "we all know" that x == y can be problematic, where x and y are floating point values, this question is a bit more specific: int x = random.Next(SOME_UPPER_LIMIT); float r = x; // Is the following ALWAYS true? r == x Now, since the range of float of is much larger than that of integers (but the precision is insufficient to uniquely present integers at the edges), it would be nice if responses to this question also addressed which values of x the above can be guaranteed for, if it can be