Skip to content

Doc: Add information on operator precedence #5202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 22, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions doc/manual/mathematical-operations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,27 @@ expressions with side effects (such as printing) in chained comparisons.
If side effects are required, the short-circuit ``&&`` operator should
be used explicitly (see :ref:`man-short-circuit-evaluation`).

Operator Precedence
~~~~~~~~~~~~~~~~~~~

Julia applies the following order of operations, from highest precedence
to lowest:

================= =============================================================================================
Category Operators
================= =============================================================================================
Syntax ``.`` followed by ``::``
Exponentiation ``^`` and its elementwise equivalent ``.^``
Fractions ``//`` and ``.//``
Multiplication ``* / % & \`` and ``.* ./ .% .\``
Bitshifts ``<< >> >>>`` and ``.<< .>> .>>>``
Addition ``+ - | $`` and ``.+ .-``
Syntax ``: ..`` followed by ``|>``
Comparisons ``> < >= <= == === != !== <:`` and ``.> .< .>= .<= .== .!=``
Control flow ``&&`` followed by ``||`` followed by ``?``
Assignments ``= += -= *= /= //= \= ^= %= |= &= $= <<= >>= >>>=`` and ``.+= .-= .*= ./= .//= .\= .^= .%=``
================= =============================================================================================

.. _man-elementary-functions:

Elementary Functions
Expand Down
6 changes: 6 additions & 0 deletions doc/manual/noteworthy-differences.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ differences that may trip up Julia users accustomed to MATLAB:
- If ``A`` and ``B`` are arrays, ``A == B`` doesn't return an array of
booleans. Use ``A .== B`` instead. Likewise for the other boolean
operators, ``<``, ``>``, ``!=``, etc.
- The operators ``&``, ``|``, and ``$`` perform the bitwise operations and,
or, and xor, respectively, and have precedence similar to Python's bitwise
operators (not like C). They can operate on scalars or elementwise
across arrays and can be used to combine logical arrays, but note the
difference in order of operations—parentheses may be required (e.g.,
to select elements of ``A`` equal to 1 or 2 use ``(A .== 1) | (A .== 2)``).
- The elements of a collection can be passed as arguments to a function
using ``...``, as in ``xs=[1,2]; f(xs...)``.
- Julia's ``svd`` returns singular values as a vector instead of as a
Expand Down