4 ms·
on computers you can have negative zeros
by WithinReason 2y ago
on computers you can have negative zeros
- recursive 2y agoNegative zero is equal to zero, so it's not really a distinct number, just another representation of the same value.
- epidemian 2y agoIt's equal (as in, comparing them with == is true), but they are not the same value. At least in IEEE 754 floats, which is what most languages with floating point numbers use. E.g., in JS: > 1 / 0 Infinity > 1 / -0 -Infinity > 0 === -0 true > Object.is(0, -0) false
- eru 2y agoYes. In a language like C or Rust, you can cast your +0.0 and -0.0 to an integer, and print out the bit pattern. They are different.
- recursive 2y agoI think you're misunderstanding me. They are the same value, but a different representation. The equivalence of the value can be shown with math, and has nothing to do with the implementation details of IEEE 754.
- atsmyles 2y ago-0 is a notation for 1 / -infinity, so it is distinct. For addition it is not.
- pasquinelli 2y agothat's really just an encoding of the number to help you understand how the hell you got here