GNOME Bugzilla – Bug 115941
Add parens to make XL style negation precedence unambiguous
Last modified: 2008-12-02 20:15:27 UTC
While I already know what will happen to this report due to the comments on irc, I think it is important to record the issue: in current cvs, -2^2 evaluates to 4 standard mathematics would have this evaluate to -4 since the precedence of exponentiation is usually higher than the precedence of negation. the fact that XL makes the same error should not be a justification. I guess this may be a reason why we should never use a spreadsheet in a university classroom.
I have a patch that at makes the pretty printer print either -(2^2) or (-2)^2, but never -2^2. That takes some of the surprise out and as files gets saved, the expression in there will immune to future parsing changes.
I guess that means that -2^2 would be reformated to (-2)^2. That is something I can live with.
That fix is in, but jody had something over in XL that needed doing there.
*** Bug 131486 has been marked as a duplicate of this bug. ***
Note, that there are actually two different issues with -2^2: A. How should we parse those four characters? A1. -(2^2) A2. (-2)^2 [a negative constant -2] A3. (-(2))^2 [unary minus applied to constant 2] The difference between A2 and A3 does not affect the result. B. Given the Excel-introduced confusion, how should we pretty-print the various possibilities? We have solved B by introducing an extra parentheses so we clearly distinguish A1 from A2/A3. A is not really solvable. Different people desire different things. It is clearly the dominant math feeling that A1 is right. (Those same people do not recognize A2. Yet they will still claim that -2 is a member of Z, even though Z contains numbers, not unary expressions. These are awfully sloppy people.)
The parser now introduces explicit ()s in this case. There no longer is a need to change the XL side. This problem has been fixed in the development version. The fix will be available in the next major software release. Thank you for your bug report.