Well, floating-point math is a pain.
On 14 May 2018 at 18:44, Vincent Povirk vincent@codeweavers.com wrote:
OK, assuming the same exponent, I guess that works. You'd have to be careful to avoid test data that's close to a power of 2.
No, that works. Adjacent (regular) IEEE floats have adjacent integer representations. The cases where it breaks down are things like denormals, NaNs and infinities.
I'm not sure about the assumption that float and int are the same size.
They are everywhere we care about. I suppose you could introduce a C_ASSERT to make sure, but I suspect a whole bunch of other stuff would also break in case either integers or floats aren't 32-bits.
I'm also not clear on why you subtract "negative" values from INT_MIN. What case is that accounting for, and what does it mean?
It's accounting for the case where you're comparing floating point numbers of opposite signs.