This site is supported by donations to The OEIS Foundation.

Talk:Operator precedence

From OeisWiki
Jump to: navigation, search

Just for reference:

C++ operators

left to right associativity

1 LR :: scope resolution
2 RL . dirmbracc -> indirmbracc . ()fncall [ ]array elem ref
3 RL ++ postfix inc -- postfixdec ~ ! +unary -unary *unary &address of (type) sizeof new delete
4 LR ->* ptr to mbr sel .* ptr to mbr sel
5 LR * / %modulus
6 + bin add - bin min
7 << Lshift >> Rshift
8 < <= > >=
9 == eq != ineq
10 & bitwise AND
11 ^ BITWISE XOR
12 | BITWISE OR
13 && LOGICAL AND
14 LR || LOGICAL OR
15 RL ?: cond expr oper
16 RL = *= /= += -= <<= >>= &= ^= |=
17 LR ,

from Appendix 4 on p. 142 of Jean Ettinger, Programming in C++ Houndmills, Basingstoke, Hampshire (1994) Macmillan AND (for associativity and descriptions) Appendix D Operator Tables pp. 426 - 428 Amir Afzal Pure C++ Porgramming Upper Saddle River NJ Prentice Hall (2002)

Javascript operators

1 Parentheses, function call or array subscript
2 !, ~, -, ++, -(slightly longer dash), typeof, new, void, delete
3 *, /, %
4 +, -
5 <<, >>, >>>
6 <, <=, > >=
7 ==, != ===, !==
8 &
9 ^
10 |
11 &&
12 ||
13 ?:
14 =, +=, -=, *=, /=, %=, <<=, >>=, >>>=, &=, ^= |=
15 The comma (,) operator

from p. 93 of James Jaworski, Mastering JavaScript and JScript CITY? Sybex (1999)

Example with product

I disagree that in \prod a_i + 1 one should understand a parenthesis around the sum (although I agree with the suggestion to put 1+ before the product, but this isn't possible any more when the 1 is, e.g., a product itself). This is a product followed by an addition. As soon as the expressions get a little more involved you won't be able to continue with that kind of economy that may cost much, so the best is not to start with in the simplest cases. Another point: associativity in addition to precedence is not only required in programming. In most cases it will amount to the same as left-to-right evaluation, but in others not. Finally, one might say a word about the bad habit of some authors to put tons of unneeded parentheses, around each and every sub-expression (sometimes even around elementary terms like variables and numerical literals). Donald E. Knuth advised against (even moderate use of) unneeded parentheses in his TAOCP, but I don't remember exactly where. MFH 04:21, 29 December 2019 (EST)