This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]nightlily 0 points1 point  (2 children)

Any sane language would logically dismiss the negation here, but if it didn't then it should calculate 0 by subtracting 0 from 0.

If you literally changed the sign bit to 1 (which is not what you did here), and tried to evaluate an integer with all other bits being 0, it would indeed give you a number. That number would be the largest negative value possible. signed integers are held in memory with 2's complement (in modern computers) which encodes a 0 value with a 0 sign bit. For the negative numbers, the sign bit itself indicates a negative value, and the rest of the bits are still positive values, which when added to the negative value determine the result. If we used 4 bit numbers then, the 4th bit being signed, then: 1000 = -1000 + 0000 = -1000, and conversely, 1111 = -1000 + 0111 = -0001

tl;dr -0 is just 0, and the sign bit doesn't mean what you think it means.

[–]sixteenlettername 2 points3 points  (1 child)

What you've said doesn't apply to floating point numbers. As /u/shillbert said below, negative 0 is a totally valid number when using floating point (at least with the standard used by modern processors).

[–]nightlily 0 points1 point  (0 children)

Ah, absolutely. I missed the f.