[R] [Rd] Multiplication

Patrick Burns pburns at pburns.seanet.com
Fri Jan 6 17:42:23 CET 2006


BR>   Anyone got a counter example where unary minus is 
BR> higher than power?

Excel (at least sort of).  See

http://www.burns-stat.com/pages/Tutor/spreadsheet_addiction.html


Patrick Burns
patrick at burns-stat.com
+44 (0)20 8525 0696
http://www.burns-stat.com
(home of S Poetry and "A Guide for the Unwilling S User")

Barry Rowlingson wrote:

>[crossed over to r-help since its not a bug and not a devel thing any more]
>
>Thomas Lumley wrote:
>
>  
>
>>So is -2^2.  The precedence of ^ is higher than that of unary minus. It 
>>may be surprising, but it *is* documented and has been in S for a long 
>>time.
>>    
>>
>
>And just about every other programming language:
>
>Matlab:
>
> >> -2^2
>
>ans =
>
>     -4
>
>
>Maxima:
>
>(C1) -2^2;
>(D1) 				      - 4
>
>Fortran:
>       print *,-2**2
>  -4
>
>Perl:
>
>$ perl -e 'print -2^2'
>4294967292
>
>  Oops. I mean:
>
>$ perl -e 'print -2**2'
>-4
>
>  The precendence of operators is remarkably consistent over programming 
>languages over time. It seems natural for me now that ^ is done before 
>unary minus, but I don't know if that's because I've been doing that for 
>25 years or because its really more natural.
>
>  Anyone got a counter example where unary minus is higher than power?
>
>Barry
>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
>
>
>  
>




More information about the R-help mailing list