|
|
|
|
|
by BeetleB
971 days ago
|
|
> +0 + -0 = +0 vs. -0 + +0 = -0 These are not exceptions. First, I will note that your result above depends on the rounding mode. Second, IEEE 754 mandates that +0 and -0 are equal (i.e. any equality operator should return True when comparing these two). Therefore both expressions are equal. NaN has several representations in bits, but they are all "equal" to one another.[1] If an operation gives you NaN, then so will doing it commutatively. It doesn't matter that the underlying bits are the same. [1] Except for the signaling aspect. But I believe that is preserved in commutative operations. |
|
Also, yes, +0 == -0, but they can produce different results when used in the same expression, so the distinction does matter (although this doesn't affect commutativity, which is the larger point). For example, let f(x) = 1 / x. Then f(+0) = +inf, f(-0) = -inf.
I also agree with you about NaN, that's why I mentioned having to go outside floating point numbers (bit-casting).