Bug 38824 - [EasyHack] Correct interpretation of -x^y
Summary: [EasyHack] Correct interpretation of -x^y
Status: RESOLVED DUPLICATE of bug 37271
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
unspecified
Hardware: Other All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords: difficultyInteresting, easyHack, skillCpp, skillDebug
: 38999 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-06-30 08:09 UTC by Björn Michaelsen
Modified: 2020-08-31 12:05 UTC (History)
3 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Björn Michaelsen 2011-06-30 08:09:58 UTC
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.
Comment 1 Markus Mohrhard 2011-07-06 02:30:30 UTC
*** Bug 38999 has been marked as a duplicate of this bug. ***
Comment 2 Regina Henschel 2011-07-06 14:15:46 UTC
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.
Comment 3 wv99999 2011-07-07 13:38:07 UTC
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?
Comment 4 Björn Michaelsen 2011-07-08 11:20:19 UTC

*** This bug has been marked as a duplicate of bug 37271 ***
Comment 5 Robinson Tryon (qubit) 2015-12-15 23:23:40 UTC
Migrating Whiteboard tags to Keywords: (EasyHack DifficultyInteresting SkillCpp SkillDebug)
[NinjaEdit]