Since floating point operations are not associative, I wonder if it is legal for compilers to rearrange them. Maybe that’s what’s happening here?
Note: That is of course no longer true under -ffast-math.
Usually, but not always. (+0) + (-0) yields (+0), while (-0) + (+0) yields (-0).
IEEE 754-2008
> Section 6.3 The sign bit
> When the sum of two operands with opposite signs (or the difference of two operands with like signs) is exactly zero, the sign of that sum (or difference) shall be +0 in all rounding-direction attributes except roundTowardNegative; under that attribute, the sign of an exact zero sum (or difference) shall be −0. However, x + x = x − (−x) retains the same sign as x even when x is zero.
No quote for IEEE 754-1985 because I didn't want to type it out and it is mostly the same.