On a ones-complement platform, what would the following code print?
#include
int main() {
int i = 1, j = -1;
std::cout << i+
Indeed adding n
to -n
should give you a negative zero. But the generation of -0 doesn't happen in practice since 1's complement addition uses a technique called a complementing subtractor (the second argument is complemented and subtracted from the first).
(The idiomatic way of getting a signed floating point zero doesn't apply here since you can't divide an integer by zero).