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


On 30/03/16 13:52, Alex McMurchy wrote:
Unless I'm misremembering my maths  -2² would be +4 and -(2²) would be -4

So in my mind no bug.

Just a matter of convention. Unfortunately where there's one, there's another.......

It seems that perl, python and php differ. Perl and python I've tried and it's so, php's manual puts exponentiation at higher precedence than unary - (http://php.net/manual/en/language.operators.precedence.php) although the ** operator is new in php 5.6 so I can't check offhand.

eg
mike@spock> python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print -3 ** 2
-9


Excel is documented as Calc's order, ie the opposite.

Javascript seems to agree with Excel.
(https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Operator_Precedence)

Fortran (remember that?) puts - below **
(https://www.fortran.com/F77_std/rjcnf0001-sh-6.html)
that page says explicitly
"For example, in the expression

- A ** 2

the exponentiation operator (**) has precedence over the negation operator (-) .... The interpretation of the above expression is the same as the interpretation of the expression

- (A ** 2)
"


Oddly, I can't find any strictly /mathematical/ guideline! Anyone have the maths students' guide to operator precedence?


It looks as though opinion is divided.


I'd suggest always using brackets to be sure and clear. In any case, it really needs documenting for Calc.



--
Mike Scott (unet2 <at> [deletethis] scottsonline.org.uk)
Harlow Essex England

--
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.