When I was debugging code, I found that GCC and Clang both yield nan for 0.0/0.0
which is what I was expecting, but GCC yields an nan with the sign bit set to 1, while Clang sets it to 0 (in agreement with ICC, if I remember correctly).
Now apparently both forms are allowed, but I keep wondering why 0.0/0.0
would make GCC output a "negative" result (printing it gives -nan
), and -(0.0/0.0)
gives a "positive" result? What is even more confusing is that -0.0/0.0
is "negative" again. Is this a constant folding weirdness?
edit
Actually, it's the constant folding that makes it a positive nan. If I force the computation at runtime, I get negative nan on both GCC and Clang
volatile float zero = 0.0;
std::cout << (zero/zero); // -nan
Can someone sched some light on this please? Is the sign bit set to 1 on the x86 FPU?