I am doing some mathematical calculations (trying to convert Matlab code into C++, using VS2010) and I need to be able to tell if at some point I get a negative 0.
According to the IEEE standard -0/+0 differ only in the sign bit (the rest are 0).
I have used the following piece of code (post) to interpret my double as a unsigned char
double f = -5;
unsigned char *c = reinterpret_cast<unsigned char *>(&f);
for(int i=(sizeof(double)-1); i>=0; i--){
printf("%02X", c[i]);
}
Trying it with 5/-5 I get the expected result:
C014000000000000 (-5)
4014000000000000 (5)
But when I try it with 0/-0 I get only zeros in both case. VS2010 states that they are IEEE compliant (msdn) so I'm not sure which part of it I'm not getting.
If 0/-0 are indeed stored in the memory in the exact same way, there is no way I can tell them apart if I need to so I should stop wasting my time :) Right?