Background: Mathematically -x^2 should calculate the x^2 part first then the minus operator, but Calc currently calculates that as if its (-x)^2. We need to change the order of calculation in a mathematically correct way. One caveat is that, when importing an Excel document, we need to put parensethes around the -x term since Excel behaves like Calc currently does. Code pointers: All parsing of formula expression takes place in ScCompiler. Especially pay close attention to ScCompiler::NextNewToken() and ScCompiler::NextSymbol(), to see how that string is compiled into tokens. Skills: building, debugging, medium C++, ability to read and understand C++ code.
*** Bug 38999 has been marked as a duplicate of this bug. ***
I disagree to change the order, because the current order is specified in this way in ODF1.2. I propose to insert parenthesis when the formula is entered, as Gnumeric does it. There is already issue 37271 with the same discussion.
More information on order of processing may be found in <http://en.wikipedia.org/wiki/Order_of_operations> Refer in particular to the paragraph "Gaps in the standard" This may be summarized by stating that programming languages (and Calc is one of them) need to deal with more operators than mathematicians prior to the invention of each programming language were wont to do. Thus, the cohesion regarding order of processing that was assumed to exist within the mathematics community proved to be an illusion when new programming languages were created. Nobody ever had the authority to lay down the law, and commercial pressures now mean that we are stuck with it and will never have a uniform rule. If the order of processing is not fixed (or fixable) in the computer world, different behavior in different languages cannot be termed 'bug' in a strict sense. Therefore, it appears that Björn Michaelsen, and my own, mathematics education needs to be amended. If that is so, the answer would lie in educating all Calc users rather than to change the code. Could we all agree that the appropriate solution is to have an entry in the help file named 'Order of processing' to explain the situation? Further, to draw the user's attention to possible trouble, it would be great to have the help assistant to pop up when it detects -A1^2 in a cell and ask the user whether he wants this to be interpreted as (-A1)^2?
*** This bug has been marked as a duplicate of bug 37271 ***
Migrating Whiteboard tags to Keywords: (EasyHack DifficultyInteresting SkillCpp SkillDebug) [NinjaEdit]