A signed int reserves one bit to signify whether a number is positive or
negative. In light of this, a colleague asked me whether there existed an
int in C++ that was -0, a zero with the negative bit set. I was intrigued
by this, so I tried the following code:
#include <stdio.h>
int main(int, char**) {
int a(-0);
printf("a=%d\n" , a);
if ( a==0 ) printf("a==0\n" );
if ( a==-0 ) printf("a==-0\n");
return 0;
}
The output is:
a=0
a==0
a==-0
So it seems that no such number can be used in C++, and speaking of
mathematical numbers, it makes perfect sense, but what is actually going on
"behing the curtains" in C++ since the compiled code can't discern between
+0 and -0 ?
--
Christian Stigen Larsen -- http://sublevel3.org/~csl/