Recently I studied the complement system of the representation of numbers and from what I understand there are two options for the number 0. There is a negative zero (-0) and positive zero (+0).
My question is, on which architecture complements how exactly does this anomaly be considered in C? C makes a distinction between -0 and +0, or both of these forms are simply treated as zero.
If it is that both +0 and -0 return TRUE when checking for zero, then I wonder how the following code example will work, which calculates the number of given bits in integers if we enter -0 as our input.
int bitcount(int x) { int b; for (b = 0; x != 0; b++) x &= (x-1); return b; }
Since -0, in one addition, all its bits set to 1, -0 should return the largest number of bits set from any other number; however, it seems that this code will complete the test condition of the loop x != 0 and not even go into the loop, which will give an incorrect result.
It would be possible somehow in C in architecture with one addition to make the loop condition sensitive to positive zeros, as in: x != +0 Also, if I subtracted 1 from +0, I would get -0 or -1 . In other words, +0 - 1 = -0 in the same complement architecture?
In general, so as not to go too far in this discussion, I just wonder how C considers the features of the number 0 in architecture with the addition.
c ones-complement
Adam Bak Jul 22 '17 at 23:54 on 2017-07-22 23:54
source share