Oi, for some reason I thought the sign bit was used for the signalling toggle ????? It makes even less sense that it returns -NaN though. Maybe it's just setting all the bits?
And yeah, the NaN and -NaN thing is annoying, much like having separate 0 and -0 (let's face it, how often is a signed 0 useful?).
EDIT: checked now, the value returned is 0xFFC00000. OK huh, I'm completely clueless what's the logic behind this now. I know that in practice this doesn't matter at all (a NaN is still a NaN in the end) but still, I'm curious.
EDIT 2: of course I should have remembered that the C and C++ standards would get in the way. What happens when I build normally:
+0 / +0 = -NaN
+0 / -0 = -NaN
-0 / +0 = -NaN
-0 / -0 = -NaN
What happens when I tell the compiler to ignore trying to preserve floating point ordering and such (i.e. -ffast-math in GCC):
+0 / +0 = 1
+0 / -0 = -NaN
-0 / +0 = -NaN
-0 / -0 = 1
For those who wonder, this is the test program (assumes that both int and float are 4 bytes):
#include <stdio.h>
#include <string.h>
int main() {
float z1, z2;
float f;
unsigned i;
z1 = 0.0f;
z2 = 0.0f;
z2 = -z2;
memcpy(&i, &z1, 4);
printf("+0 = %08X\n", i);
memcpy(&i, &z2, 4);
printf("-0 = %08X\n", i);
f = z1 / z1;
memcpy(&i, &f, 4);
printf("+0 / +0 = %08X\n", i);
f = z1 / z2;
memcpy(&i, &f, 4);
printf("+0 / -0 = %08X\n", i);
f = z2 / z1;
memcpy(&i, &f, 4);
printf("-0 / +0 = %08X\n", i);
f = z2 / z2;
memcpy(&i, &f, 4);
printf("-0 / -0 = %08X\n", i);
return 0;
}
EDIT 3: OK nevermind it was an optimization getting in the way, dividing by itself gets optimized to 1 >_> Though for some reason this happens even with -O0 (which literally should generate the most unoptimized code it could ever attempt to make), so I guess this may be happening in the processor itself. Using separate variables makes it work as intended (gives -NaN in all four cases).
Don't pay much attention to "the hedgehog" in my nick, it's just because "Sik" was already taken =/ By the way, Sik is pronounced like seek, not like sick.