|
|
|
|
|
by jacobolus
2644 days ago
|
|
> number is never supposed to change (sign or magnitude) when you add 0 to it In the “real numbers”, zero doesn’t have a sign at all, and -0 and 0 mean precisely the same thing. Floating point is an approximation which needs to make some choices about edge cases, for the sake of practical uses (for instance it is useful to distinguish negative underflow from positive underflow, so there is an extra -0 value included). The behavior that 0 - 0 or -0 + 0 produces 0 as output is not an unreasonable choice (it is what I would expect, as someone with a decent amount of mathematical experience). I would not expect very many people to have the “intuition” that -0 + 0 or 0 - 0 should produce -0 as a result, assuming they had any intuition at all about what should happen in this edge case. |
|
----
Consider the counter-argument, that it's intuitive/correct because in math `X + (-X) = 0`:
It's true that this characteristic by itself is preserved, but where it falls apart: That final statement should be true for all X, but as demonstrated above, it's not true for -0.