Owndating org ua
I mean, you may think it’s difficult to calculate when trains from Chicago and Los Angeles will collide, but that’s just peanuts to floating-point math. Each time I think that I’ve wrapped my head around the subtleties and implications of floating-point math I find that I’m wrong and that there is some extra confounding factor that I had failed to consider.
So, the lesson to remember is that floating-point math is always more complex than you think it is.
Subtracting the signed-magnitude representation of floats using twos-complement math isn’t particularly meaningful, and the subtraction would produce a 33-bit result and overflow.
Even if we deal with these technical issues it turns out that an ULPs based comparison of floats with different signs doesn’t even make sense.
And, to be clear, float(0.1) and double(0.1) don’t have the same value, because float(0.1) has fewer binary digits, and therefore has more error.
We already know that adjacent floats have integer representations that are adjacent.
Answer two is correct (but inexact), whereas answer three is completely correct (but appears wrong).