Date: prev next · Thread: first prev next last
2016 Archives by date, by thread · List index


Hi,

lorieul schrieb:
Hello to all,

I have found a fancy behavior of Calc but I cannot decide whether it is
a bug or a "feature". Hence I was looking for your advice before posting
a bug report (if required).

That is good. It is https://bugs.documentfoundation.org/show_bug.cgi?id=37271


   1. Open LO Calc
   2. In A1 enter formula "=1-2^2" and press enter key
      The result shown is -3 which is ok since
      1-2² = 1-(2²) = 1-4 = -3
   3. In A2 enter formula "=-2^2" and press enter key
      I would expect this to be treated as -2² = -(2²) = -4
      But Calc considers it as (-2)² = +4
      Quite obviously, a work around is to define the formula as
      "=-(2^2)" which indeed returns -4

I've checked the wiki page dedicated to operators [1] but it does not
give much information on operator precedence.

 From my standpoint, both examples show an inconsistent behavior of Calc.
For me, either we should have both 1-2^2 = 1+4 = 5 and -2^2 = +4
Or we should have both 1-2^2 = 1-4 = -3 and -2^2 = -4

A minus can be a binary operator subtraction or a unary operator sign.
In "=1-2^2" there is a operand left and right of the minus, so it is a binary operator. This means calculate its operands and then subtract. In "=-2^2" there is no operand left. Therefore the minus can only be a unary operator, which means, it is a sign of the number. So Calc takes the number -2 and puts it to the power 2.


However, perhaps some of you have a different view point on the matter ?
In other words, is that a bug or is it perfectly normal ?

It is no bug, but a bad UI, because pupils are thought, that -2² is -4. One solution to fit common understanding to the formal term interpretation you can see in Gnumeric. It simple does not allow it. When the user enters =-2^2 it automatically adds brackets, so that it becomes (-2)^2 and the users knows the meaning unambiguous.

To force a result of -4 you need to tell Calc, that the minus is a binary operator. The formula "=0-2^2" would do that.


Of course changing such behavior will cause a hell lot of trouble in
existing documents… but perhaps the operator precedence should be
explicitly specified on the wiki ?

The precedence is defined in ODF http://docs.oasis-open.org/office/v1.2/os/OpenDocument-v1.2-os-part2.html#Operators

Kind regards
Regina


--
To unsubscribe e-mail to: users+unsubscribe@global.libreoffice.org
Problems? http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette
List archive: http://listarchives.libreoffice.org/global/users/
All messages sent to this list will be publicly archived and cannot be deleted

Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.