[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
precedence
From: |
John W. Eaton |
Subject: |
precedence |
Date: |
Tue, 6 Aug 2002 12:40:23 -0500 |
The documentation for Matlab on the MathWorks web site now lists
operator precedence. It may have been there for a while now, but this
is the first time I remember seeing it.
Here is their list:
1. Parentheses ()
2. Transpose (.'), power (.^), complex conjugate transpose ('),
matrix power (^)
3. Unary plus (+), unary minus (-), logical negation (~)
4. Multiplication (.*), right division (./), left division(.\),
matrix multiplication (*), matrix right division (/),
matrix left division (\)
5. Addition (+), subtraction (-)
6. Colon operator (:)
7. Less than (<), less than or equal to (<=), greater than (>),
greater than or equal to (>=), equal to (==), not equal to (~=)
8. Element-wise AND (&)
9. Element-wise OR (|)
10. Short-circuit AND (&&)
11. Short-circuit OR (||)
Ignoring the indexing operators '.' and '{' (not sure why they were
omitted from the Matlab list), the separator operators (';', ',',
'\n'), the LSHIFT (<<), RSHIFT (>>), increment (++) and decrement (--)
operators (Matlab does not have these), and all the assignment
operators (in Matlab, assignment is not an expression), Octave's
precedence list is:
1. Parentheses '('
2. Power (.^), matrix power (.^)
3. Unary plus (+), Unary minus (-), logical negation (~)
4. Transpose (.'), complex conjugate transpose ('),
5. Multiplication (.*), right division (./), left division(.\),
matrix multiplication (*), matrix right division (/),
matrix left division (\)
6. Addition (+), subtraction (-)
7. Colon operator (:)
8. Less than (<), less than or equal to (<=), greater than (>),
greater than or equal to (>=), equal to (==), not equal to (~=)
9. Element-wise AND (&), Element-wise OR (|)
10. Short-circuit AND (&&), Short-circuit OR (||)
(Note that in the latest release, they have have finally introduced
the || and && operators to do short-circuiting instead of relying on
whether the | and & operators appear in if/while conditions to decide
whether to short-circuit.)
Differences:
* In Matlab, transpose and power have the same precedence, higher
than unary +/- and negation.
* In Matlab, element-wise AND (&) has higher precedence than
element-wise OR (|), in Octave they have the same precedence.
* In Matlab, short-circuit AND (&&) has higher precedence than
short-circuit OR (||), in Octave they have the same precedence.
How much trouble would it cause if Octave were changed to match the
Matlab precedence rules?
Thanks,
jwe
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------
- precedence,
John W. Eaton <=