I am not familiar enough with FPU to comment with any certainty, but I assume that the compiler allows the existing value, which in his opinion should be equal to x , to sit in this comparison. Perhaps you go y = x + 20.; y = y - 20; y = x + 20.; y = y - 20; y already on the FP stack, so instead of loading x compiler simply compares with y . But due to rounding errors, y not quite 0.0 , as expected, and you get the odd results you see.
For a better explanation: Why cos (x)! = Cos (y), although x == y? from C ++ FAQ lite. This is part of what I'm trying to understand, I just could not remember exactly where I read it so far.
Changing the const reference fixes this because the compiler is concerned about the alias. It forces the load from x , because it cannot be assumed that its value did not change at some point after y , and since x is actually exactly 0.0 [which appears in every floating-point format, I am "familiar") rounding errors disappear.
I'm sure MS provides a pragma that allows you to set FP flags based on each function. Or you can transfer this procedure to a separate file and provide these flags for the file. In any case, this may prevent your program from suffering completely in order to maintain this ordinary joy.
source share