Mercurial > hg > octave-lyh
annotate doc/interpreter/expr.txi @ 12627:002948ae5bc0
fix precedence level of transpose operators (bug #32533)
* Makefile.am: Note 16 shift/reduce conflicts in oct-parse.yy.
* lex.ll (BIN_OP_RETURN_INTERNAL, XBIN_OP_RETURN_INTERNAL): New macros.
(BIN_OP_RETURN): Define using BIN_OP_RETURN_INTERNAL.
("--", "++"): Use XBIN_OP_RETURN_INTERNAL to set
lexer_flags.quote_is_transpose to true.
* oct-parse.yy: Set precedence level as documented and for
compatibility with Matlab. Don't set precedence for comma, semicolon
or newline characters.
(UNARY, PLUS_PLUS, MINUS_MINUS, EXPR_NOT): Associativity is now right,
not left.
(oper_expr): New non-terminal. Merge all operator non-terminals
except postfix increment and decrement into oper_expr.
(prefix_expr, binary_expr): Delete unused non-terminals.
* expr.txi: Document precedence to match reality.
* test_parser.m: Fix tests for increment and decrement operators to
match current behavior.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 21 Apr 2011 17:41:56 -0400 |
parents | 99babbf683ff |
children | 990762e784fe |
rev | line source |
---|---|
11523 | 1 @c Copyright (C) 1996-2011 John W. Eaton |
7018 | 2 @c |
3 @c This file is part of Octave. | |
4 @c | |
5 @c Octave is free software; you can redistribute it and/or modify it | |
6 @c under the terms of the GNU General Public License as published by the | |
7 @c Free Software Foundation; either version 3 of the License, or (at | |
8 @c your option) any later version. | |
9 @c | |
10 @c Octave is distributed in the hope that it will be useful, but WITHOUT | |
11 @c ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
12 @c FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
13 @c for more details. | |
14 @c | |
15 @c You should have received a copy of the GNU General Public License | |
16 @c along with Octave; see the file COPYING. If not, see | |
17 @c <http://www.gnu.org/licenses/>. | |
3294 | 18 |
4167 | 19 @node Expressions |
3294 | 20 @chapter Expressions |
21 @cindex expressions | |
22 | |
23 Expressions are the basic building block of statements in Octave. An | |
24 expression evaluates to a value, which you can print, test, store in a | |
25 variable, pass to a function, or assign a new value to a variable with | |
26 an assignment operator. | |
27 | |
28 An expression can serve as a statement on its own. Most other kinds of | |
29 statements contain one or more expressions which specify data to be | |
30 operated on. As in other languages, expressions in Octave include | |
31 variables, array references, constants, and function calls, as well as | |
32 combinations of these with various operators. | |
33 | |
34 @menu | |
35 * Index Expressions:: | |
36 * Calling Functions:: | |
37 * Arithmetic Ops:: | |
38 * Comparison Ops:: | |
39 * Boolean Expressions:: | |
40 * Assignment Ops:: | |
41 * Increment Ops:: | |
42 * Operator Precedence:: | |
43 @end menu | |
44 | |
4167 | 45 @node Index Expressions |
3294 | 46 @section Index Expressions |
47 | |
48 @opindex ( | |
49 @opindex ) | |
11403
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
50 @opindex : |
3294 | 51 |
52 An @dfn{index expression} allows you to reference or extract selected | |
53 elements of a matrix or vector. | |
54 | |
55 Indices may be scalars, vectors, ranges, or the special operator | |
56 @samp{:}, which may be used to select entire rows or columns. | |
57 | |
5679 | 58 Vectors are indexed using a single index expression. Matrices may be |
59 indexed using one or two indices. When using a single index | |
60 expression, the elements of the matrix are taken in column-first order; | |
61 the dimensions of the output match those of the index expression. For | |
62 example, | |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10711
diff
changeset
|
63 |
5679 | 64 @example |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9159
diff
changeset
|
65 @group |
12546
39ca02387a32
Improve docstrings for a number of functions.
Rik <octave@nomad.inbox5.com>
parents:
12544
diff
changeset
|
66 a(2) # a scalar |
39ca02387a32
Improve docstrings for a number of functions.
Rik <octave@nomad.inbox5.com>
parents:
12544
diff
changeset
|
67 a(1:2) # a row vector |
39ca02387a32
Improve docstrings for a number of functions.
Rik <octave@nomad.inbox5.com>
parents:
12544
diff
changeset
|
68 a([1; 2]) # a column vector |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9159
diff
changeset
|
69 @end group |
5679 | 70 @end example |
71 | |
72 As a special case, when a colon is used as a single index, the output | |
73 is a column vector containing all the elements of the vector or matrix. | |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10711
diff
changeset
|
74 For example: |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10711
diff
changeset
|
75 |
5679 | 76 @example |
12546
39ca02387a32
Improve docstrings for a number of functions.
Rik <octave@nomad.inbox5.com>
parents:
12544
diff
changeset
|
77 a(:) # a column vector |
5679 | 78 @end example |
79 | |
3294 | 80 Given the matrix |
81 | |
82 @example | |
83 a = [1, 2; 3, 4] | |
84 @end example | |
85 | |
86 @noindent | |
87 all of the following expressions are equivalent | |
88 | |
89 @example | |
90 @group | |
12546
39ca02387a32
Improve docstrings for a number of functions.
Rik <octave@nomad.inbox5.com>
parents:
12544
diff
changeset
|
91 a(1, [1, 2]) |
39ca02387a32
Improve docstrings for a number of functions.
Rik <octave@nomad.inbox5.com>
parents:
12544
diff
changeset
|
92 a(1, 1:2) |
39ca02387a32
Improve docstrings for a number of functions.
Rik <octave@nomad.inbox5.com>
parents:
12544
diff
changeset
|
93 a(1, :) |
3294 | 94 @end group |
95 @end example | |
96 | |
97 @noindent | |
98 and select the first row of the matrix. | |
99 | |
9159 | 100 In general, an array with @samp{n} dimensions can be indexed using @samp{m} |
101 indices. If @code{n == m}, each index corresponds to its respective dimension. | |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10711
diff
changeset
|
102 The set of index tuples determining the result is formed by the Cartesian |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10711
diff
changeset
|
103 product of the index vectors (or ranges or scalars). If @code{n < m}, then the |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10711
diff
changeset
|
104 array is padded by trailing singleton dimensions. If @code{n > m}, the last |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10711
diff
changeset
|
105 @code{n-m+1} dimensions are folded into a single dimension with extent equal to |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10711
diff
changeset
|
106 product of extents of the original dimensions. |
9159 | 107 |
5016 | 108 @c FIXED -- sections on variable prefer_zero_one_indexing were removed |
3294 | 109 |
5016 | 110 Indexing a scalar with a vector of ones can be used to create a |
3294 | 111 vector the same size as the index vector, with each element equal to |
112 the value of the original scalar. For example, the following statements | |
113 | |
114 @example | |
115 @group | |
116 a = 13; | |
12546
39ca02387a32
Improve docstrings for a number of functions.
Rik <octave@nomad.inbox5.com>
parents:
12544
diff
changeset
|
117 a(ones (1, 4)) |
3294 | 118 @end group |
119 @end example | |
120 | |
121 @noindent | |
122 produce a vector whose four elements are all equal to 13. | |
123 | |
124 Similarly, indexing a scalar with two vectors of ones can be used to | |
125 create a matrix. For example the following statements | |
126 | |
127 @example | |
128 @group | |
129 a = 13; | |
12546
39ca02387a32
Improve docstrings for a number of functions.
Rik <octave@nomad.inbox5.com>
parents:
12544
diff
changeset
|
130 a(ones (1, 2), ones (1, 3)) |
3294 | 131 @end group |
132 @end example | |
133 | |
134 @noindent | |
135 create a 2 by 3 matrix with all elements equal to 13. | |
136 | |
9159 | 137 The last example could also be written as |
138 | |
139 @example | |
140 @group | |
141 13 (ones (2, 3)) | |
142 @end group | |
143 @end example | |
144 | |
145 It should be, noted that @code{ones (1, n)} (a row vector of ones) results in a | |
146 range (with zero increment), and is therefore more efficient when used in index | |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10711
diff
changeset
|
147 expression than other forms of @dfn{ones}. In particular, when @samp{r} is a |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10711
diff
changeset
|
148 row vector, the expressions |
9159 | 149 |
150 @example | |
151 r(ones (1, n), :) | |
152 @end example | |
153 | |
154 @example | |
155 r(ones (n, 1), :) | |
156 @end example | |
157 | |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10828
diff
changeset
|
158 @noindent |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9159
diff
changeset
|
159 will produce identical results, but the first one will be significantly |
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9159
diff
changeset
|
160 faster, at least for @samp{r} and @samp{n} large enough. The reason is that |
9159 | 161 in the first case the index is kept in a compressed form, which allows Octave |
162 to choose a more efficient algorithm to handle the expression. | |
163 | |
164 In general, for an user unaware of these subtleties, it is best to use | |
165 the function @dfn{repmat} for spreading arrays into bigger ones. | |
3294 | 166 |
9037
4cb9f994dcec
Documentation cleanup of var.texi, expr.texi, eval.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
167 It is also possible to create a matrix with different values. The |
6939 | 168 following example creates a 10 dimensional row vector @math{a} containing |
6642 | 169 the values |
170 @tex | |
171 $a_i = \sqrt{i}$. | |
172 @end tex | |
173 @ifnottex | |
174 a(i) = sqrt(i). | |
175 @end ifnottex | |
176 | |
177 @example | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9159
diff
changeset
|
178 @group |
6642 | 179 for i = 1:10 |
180 a(i) = sqrt (i); | |
181 endfor | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9159
diff
changeset
|
182 @end group |
6642 | 183 @end example |
184 | |
185 @noindent | |
3294 | 186 Note that it is quite inefficient to create a vector using a loop like |
187 the one shown in the example above. In this particular case, it would | |
188 have been much more efficient to use the expression | |
189 | |
190 @example | |
191 a = sqrt (1:10); | |
192 @end example | |
193 | |
194 @noindent | |
195 thus avoiding the loop entirely. In cases where a loop is still | |
196 required, or a number of values must be combined to form a larger | |
197 matrix, it is generally much faster to set the size of the matrix first, | |
198 and then insert elements using indexing commands. For example, given a | |
199 matrix @code{a}, | |
200 | |
201 @example | |
202 @group | |
203 [nr, nc] = size (a); | |
204 x = zeros (nr, n * nc); | |
205 for i = 1:n | |
3602 | 206 x(:,(i-1)*nc+1:i*nc) = a; |
3294 | 207 endfor |
208 @end group | |
209 @end example | |
210 | |
211 @noindent | |
212 is considerably faster than | |
213 | |
214 @example | |
215 @group | |
216 x = a; | |
217 for i = 1:n-1 | |
218 x = [x, a]; | |
219 endfor | |
220 @end group | |
221 @end example | |
222 | |
223 @noindent | |
224 particularly for large matrices because Octave does not have to | |
225 repeatedly resize the result. | |
226 | |
6549 | 227 @DOCSTRING(sub2ind) |
228 | |
229 @DOCSTRING(ind2sub) | |
230 | |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11403
diff
changeset
|
231 @DOCSTRING(isindex) |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11403
diff
changeset
|
232 |
12544
3ba6e702e6fd
Add allow_noninteger_range_as_index to documentation.
Rik <octave@nomad.inbox5.com>
parents:
12543
diff
changeset
|
233 @DOCSTRING(allow_noninteger_range_as_index) |
3ba6e702e6fd
Add allow_noninteger_range_as_index to documentation.
Rik <octave@nomad.inbox5.com>
parents:
12543
diff
changeset
|
234 |
4167 | 235 @node Calling Functions |
3294 | 236 @section Calling Functions |
237 | |
238 A @dfn{function} is a name for a particular calculation. Because it has | |
239 a name, you can ask for it by name at any point in the program. For | |
240 example, the function @code{sqrt} computes the square root of a number. | |
241 | |
242 A fixed set of functions are @dfn{built-in}, which means they are | |
243 available in every Octave program. The @code{sqrt} function is one of | |
244 these. In addition, you can define your own functions. | |
245 @xref{Functions and Scripts}, for information about how to do this. | |
246 | |
247 @cindex arguments in function call | |
248 The way to use a function is with a @dfn{function call} expression, | |
249 which consists of the function name followed by a list of | |
9037
4cb9f994dcec
Documentation cleanup of var.texi, expr.texi, eval.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
250 @dfn{arguments} in parentheses. The arguments are expressions which give |
3294 | 251 the raw materials for the calculation that the function will do. When |
252 there is more than one argument, they are separated by commas. If there | |
253 are no arguments, you can omit the parentheses, but it is a good idea to | |
254 include them anyway, to clearly indicate that a function call was | |
255 intended. Here are some examples: | |
256 | |
257 @example | |
258 @group | |
259 sqrt (x^2 + y^2) # @r{One argument} | |
260 ones (n, m) # @r{Two arguments} | |
261 rand () # @r{No arguments} | |
262 @end group | |
263 @end example | |
264 | |
265 Each function expects a particular number of arguments. For example, the | |
266 @code{sqrt} function must be called with a single argument, the number | |
267 to take the square root of: | |
268 | |
269 @example | |
270 sqrt (@var{argument}) | |
271 @end example | |
272 | |
273 Some of the built-in functions take a variable number of arguments, | |
274 depending on the particular usage, and their behavior is different | |
275 depending on the number of arguments supplied. | |
276 | |
277 Like every other expression, the function call has a value, which is | |
278 computed by the function based on the arguments you give it. In this | |
279 example, the value of @code{sqrt (@var{argument})} is the square root of | |
280 the argument. A function can also have side effects, such as assigning | |
281 the values of certain variables or doing input or output operations. | |
282 | |
283 Unlike most languages, functions in Octave may return multiple values. | |
284 For example, the following statement | |
285 | |
286 @example | |
287 [u, s, v] = svd (a) | |
288 @end example | |
289 | |
290 @noindent | |
291 computes the singular value decomposition of the matrix @code{a} and | |
292 assigns the three result matrices to @code{u}, @code{s}, and @code{v}. | |
293 | |
294 The left side of a multiple assignment expression is itself a list of | |
295 expressions, and is allowed to be a list of variable names or index | |
296 expressions. See also @ref{Index Expressions}, and @ref{Assignment Ops}. | |
297 | |
298 @menu | |
299 * Call by Value:: | |
300 * Recursion:: | |
301 @end menu | |
302 | |
4167 | 303 @node Call by Value |
3294 | 304 @subsection Call by Value |
305 | |
306 In Octave, unlike Fortran, function arguments are passed by value, which | |
307 means that each argument in a function call is evaluated and assigned to | |
308 a temporary location in memory before being passed to the function. | |
309 There is currently no way to specify that a function parameter should be | |
310 passed by reference instead of by value. This means that it is | |
8347
fa78cb8d8a5c
corrections for typos
Brian Gough<bjg@network-theory.co.uk>
parents:
8235
diff
changeset
|
311 impossible to directly alter the value of a function parameter in the |
3294 | 312 calling function. It can only change the local copy within the function |
313 body. For example, the function | |
314 | |
315 @example | |
316 @group | |
317 function f (x, n) | |
318 while (n-- > 0) | |
319 disp (x); | |
320 endwhile | |
321 endfunction | |
322 @end group | |
323 @end example | |
324 | |
325 @noindent | |
326 displays the value of the first argument @var{n} times. In this | |
327 function, the variable @var{n} is used as a temporary variable without | |
328 having to worry that its value might also change in the calling | |
329 function. Call by value is also useful because it is always possible to | |
330 pass constants for any function parameter without first having to | |
331 determine that the function will not attempt to modify the parameter. | |
332 | |
333 The caller may use a variable as the expression for the argument, but | |
334 the called function does not know this: it only knows what value the | |
335 argument had. For example, given a function called as | |
336 | |
337 @example | |
338 @group | |
339 foo = "bar"; | |
340 fcn (foo) | |
341 @end group | |
342 @end example | |
343 | |
344 @noindent | |
345 you should not think of the argument as being ``the variable | |
346 @code{foo}.'' Instead, think of the argument as the string value, | |
347 @code{"bar"}. | |
348 | |
349 Even though Octave uses pass-by-value semantics for function arguments, | |
350 values are not copied unnecessarily. For example, | |
351 | |
352 @example | |
353 @group | |
354 x = rand (1000); | |
355 f (x); | |
356 @end group | |
357 @end example | |
358 | |
359 @noindent | |
360 does not actually force two 1000 by 1000 element matrices to exist | |
361 @emph{unless} the function @code{f} modifies the value of its | |
362 argument. Then Octave must create a copy to avoid changing the | |
363 value outside the scope of the function @code{f}, or attempting (and | |
364 probably failing!) to modify the value of a constant or the value of a | |
365 temporary result. | |
366 | |
4167 | 367 @node Recursion |
3294 | 368 @subsection Recursion |
369 @cindex factorial function | |
370 | |
6939 | 371 With some restrictions@footnote{Some of Octave's functions are |
3294 | 372 implemented in terms of functions that cannot be called recursively. |
373 For example, the ODE solver @code{lsode} is ultimately implemented in a | |
374 Fortran subroutine that cannot be called recursively, so @code{lsode} | |
375 should not be called either directly or indirectly from within the | |
376 user-supplied function that @code{lsode} requires. Doing so will result | |
6642 | 377 in an error.}, recursive function calls are allowed. A |
3294 | 378 @dfn{recursive function} is one which calls itself, either directly or |
379 indirectly. For example, here is an inefficient@footnote{It would be | |
380 much better to use @code{prod (1:n)}, or @code{gamma (n+1)} instead, | |
381 after first checking to ensure that the value @code{n} is actually a | |
382 positive integer.} way to compute the factorial of a given integer: | |
383 | |
384 @example | |
385 @group | |
386 function retval = fact (n) | |
387 if (n > 0) | |
388 retval = n * fact (n-1); | |
389 else | |
390 retval = 1; | |
391 endif | |
392 endfunction | |
393 @end group | |
394 @end example | |
395 | |
396 This function is recursive because it calls itself directly. It | |
397 eventually terminates because each time it calls itself, it uses an | |
398 argument that is one less than was used for the previous call. Once the | |
399 argument is no longer greater than zero, it does not call itself, and | |
400 the recursion ends. | |
401 | |
402 The built-in variable @code{max_recursion_depth} specifies a limit to | |
403 the recursion depth and prevents Octave from recursing infinitely. | |
404 | |
3371 | 405 @DOCSTRING(max_recursion_depth) |
3294 | 406 |
4167 | 407 @node Arithmetic Ops |
3294 | 408 @section Arithmetic Operators |
409 @cindex arithmetic operators | |
410 @cindex operators, arithmetic | |
411 @cindex addition | |
412 @cindex subtraction | |
413 @cindex multiplication | |
414 @cindex matrix multiplication | |
415 @cindex division | |
416 @cindex quotient | |
417 @cindex negation | |
418 @cindex unary minus | |
419 @cindex exponentiation | |
420 @cindex transpose | |
421 @cindex Hermitian operator | |
422 @cindex transpose, complex-conjugate | |
423 @cindex complex-conjugate transpose | |
424 | |
425 The following arithmetic operators are available, and work on scalars | |
426 and matrices. | |
427 | |
428 @table @code | |
429 @item @var{x} + @var{y} | |
430 @opindex + | |
431 Addition. If both operands are matrices, the number of rows and columns | |
432 must both agree. If one operand is a scalar, its value is added to | |
433 all the elements of the other operand. | |
434 | |
435 @item @var{x} .+ @var{y} | |
436 @opindex .+ | |
437 Element by element addition. This operator is equivalent to @code{+}. | |
438 | |
439 @item @var{x} - @var{y} | |
440 @opindex - | |
441 Subtraction. If both operands are matrices, the number of rows and | |
442 columns of both must agree. | |
443 | |
444 @item @var{x} .- @var{y} | |
445 Element by element subtraction. This operator is equivalent to @code{-}. | |
446 | |
447 @item @var{x} * @var{y} | |
448 @opindex * | |
449 Matrix multiplication. The number of columns of @var{x} must agree | |
450 with the number of rows of @var{y}. | |
451 | |
452 @item @var{x} .* @var{y} | |
453 @opindex .* | |
454 Element by element multiplication. If both operands are matrices, the | |
455 number of rows and columns must both agree. | |
456 | |
457 @item @var{x} / @var{y} | |
458 @opindex / | |
459 Right division. This is conceptually equivalent to the expression | |
460 | |
461 @example | |
462 (inverse (y') * x')' | |
463 @end example | |
464 | |
465 @noindent | |
466 but it is computed without forming the inverse of @var{y'}. | |
467 | |
468 If the system is not square, or if the coefficient matrix is singular, | |
469 a minimum norm solution is computed. | |
470 | |
471 @item @var{x} ./ @var{y} | |
472 @opindex ./ | |
473 Element by element right division. | |
474 | |
475 @item @var{x} \ @var{y} | |
476 @opindex \ | |
477 Left division. This is conceptually equivalent to the expression | |
478 | |
479 @example | |
480 inverse (x) * y | |
481 @end example | |
482 | |
483 @noindent | |
484 but it is computed without forming the inverse of @var{x}. | |
485 | |
486 If the system is not square, or if the coefficient matrix is singular, | |
487 a minimum norm solution is computed. | |
488 | |
489 @item @var{x} .\ @var{y} | |
490 @opindex .\ | |
491 Element by element left division. Each element of @var{y} is divided | |
492 by each corresponding element of @var{x}. | |
493 | |
494 @item @var{x} ^ @var{y} | |
495 @itemx @var{x} ** @var{y} | |
496 @opindex ** | |
497 @opindex ^ | |
498 Power operator. If @var{x} and @var{y} are both scalars, this operator | |
499 returns @var{x} raised to the power @var{y}. If @var{x} is a scalar and | |
500 @var{y} is a square matrix, the result is computed using an eigenvalue | |
7001 | 501 expansion. If @var{x} is a square matrix, the result is computed by |
3294 | 502 repeated multiplication if @var{y} is an integer, and by an eigenvalue |
503 expansion if @var{y} is not an integer. An error results if both | |
504 @var{x} and @var{y} are matrices. | |
505 | |
506 The implementation of this operator needs to be improved. | |
507 | |
508 @item @var{x} .^ @var{y} | |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10711
diff
changeset
|
509 @itemx @var{x} .** @var{y} |
3294 | 510 @opindex .** |
511 @opindex .^ | |
512 Element by element power operator. If both operands are matrices, the | |
513 number of rows and columns must both agree. | |
514 | |
515 @item -@var{x} | |
516 @opindex - | |
517 Negation. | |
518 | |
519 @item +@var{x} | |
520 @opindex + | |
521 Unary plus. This operator has no effect on the operand. | |
522 | |
523 @item @var{x}' | |
524 @opindex ' | |
525 Complex conjugate transpose. For real arguments, this operator is the | |
526 same as the transpose operator. For complex arguments, this operator is | |
527 equivalent to the expression | |
528 | |
529 @example | |
530 conj (x.') | |
531 @end example | |
532 | |
533 @item @var{x}.' | |
534 @opindex .' | |
535 Transpose. | |
536 @end table | |
537 | |
538 Note that because Octave's element by element operators begin with a | |
539 @samp{.}, there is a possible ambiguity for statements like | |
540 | |
541 @example | |
542 1./m | |
543 @end example | |
544 | |
545 @noindent | |
546 because the period could be interpreted either as part of the constant | |
547 or as part of the operator. To resolve this conflict, Octave treats the | |
548 expression as if you had typed | |
549 | |
550 @example | |
551 (1) ./ m | |
552 @end example | |
553 | |
554 @noindent | |
555 and not | |
556 | |
557 @example | |
558 (1.) / m | |
559 @end example | |
560 | |
561 @noindent | |
562 Although this is inconsistent with the normal behavior of Octave's | |
563 lexer, which usually prefers to break the input into tokens by | |
564 preferring the longest possible match at any given point, it is more | |
565 useful in this case. | |
566 | |
11403
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
567 @opindex ' |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
568 @DOCSTRING(ctranspose) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
569 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
570 @opindex .\ |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
571 @DOCSTRING(ldivide) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
572 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
573 @opindex - |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
574 @DOCSTRING(minus) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
575 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
576 @opindex \ |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
577 @DOCSTRING(mldivide) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
578 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
579 @opindex ** |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
580 @opindex ^ |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
581 @DOCSTRING(mpower) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
582 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
583 @opindex / |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
584 @DOCSTRING(mrdivide) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
585 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
586 @opindex * |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
587 @DOCSTRING(mtimes) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
588 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
589 @opindex + |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
590 @DOCSTRING(plus) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
591 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
592 @opindex .** |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
593 @opindex .^ |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
594 @DOCSTRING(power) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
595 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
596 @opindex ./ |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
597 @DOCSTRING(rdivide) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
598 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
599 @opindex .* |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
600 @DOCSTRING(times) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
601 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
602 @opindex .' |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
603 @DOCSTRING(transpose) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
604 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
605 @opindex - |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
606 @DOCSTRING(uminus) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
607 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
608 @opindex + |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
609 @DOCSTRING(uplus) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
610 |
4167 | 611 @node Comparison Ops |
3294 | 612 @section Comparison Operators |
613 @cindex comparison expressions | |
614 @cindex expressions, comparison | |
615 @cindex relational operators | |
616 @cindex operators, relational | |
617 @cindex less than operator | |
618 @cindex greater than operator | |
619 @cindex equality operator | |
620 @cindex tests for equality | |
621 @cindex equality, tests for | |
622 | |
623 @dfn{Comparison operators} compare numeric values for relationships | |
624 such as equality. They are written using | |
625 @emph{relational operators}. | |
626 | |
627 All of Octave's comparison operators return a value of 1 if the | |
628 comparison is true, or 0 if it is false. For matrix values, they all | |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10711
diff
changeset
|
629 work on an element-by-element basis. For example: |
3294 | 630 |
631 @example | |
632 @group | |
633 [1, 2; 3, 4] == [1, 3; 2, 4] | |
634 @result{} 1 0 | |
635 0 1 | |
636 @end group | |
637 @end example | |
638 | |
639 If one operand is a scalar and the other is a matrix, the scalar is | |
640 compared to each element of the matrix in turn, and the result is the | |
641 same size as the matrix. | |
642 | |
643 @table @code | |
644 @item @var{x} < @var{y} | |
645 @opindex < | |
646 True if @var{x} is less than @var{y}. | |
647 | |
648 @item @var{x} <= @var{y} | |
649 @opindex <= | |
650 True if @var{x} is less than or equal to @var{y}. | |
651 | |
652 @item @var{x} == @var{y} | |
653 @opindex == | |
654 True if @var{x} is equal to @var{y}. | |
655 | |
656 @item @var{x} >= @var{y} | |
657 @opindex >= | |
658 True if @var{x} is greater than or equal to @var{y}. | |
659 | |
660 @item @var{x} > @var{y} | |
661 @opindex > | |
662 True if @var{x} is greater than @var{y}. | |
663 | |
664 @item @var{x} != @var{y} | |
665 @itemx @var{x} ~= @var{y} | |
666 @opindex != | |
667 @opindex ~= | |
668 True if @var{x} is not equal to @var{y}. | |
669 @end table | |
670 | |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9245
diff
changeset
|
671 For complex numbers, the following ordering is defined: |
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9245
diff
changeset
|
672 @var{z1} < @var{z2} |
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9245
diff
changeset
|
673 iff |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10711
diff
changeset
|
674 |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9245
diff
changeset
|
675 @example |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9578
diff
changeset
|
676 @group |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9245
diff
changeset
|
677 abs(@var{z1}) < abs(@var{z2}) |
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9245
diff
changeset
|
678 || (abs(@var{z1}) == abs(@var{z2}) && arg(@var{z1}) < arg(@var{z2})) |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9578
diff
changeset
|
679 @end group |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9245
diff
changeset
|
680 @end example |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10711
diff
changeset
|
681 |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10711
diff
changeset
|
682 This is consistent with the ordering used by @dfn{max}, @dfn{min} and |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10711
diff
changeset
|
683 @dfn{sort}, but is not consistent with @sc{matlab}, which only compares the real |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10711
diff
changeset
|
684 parts. |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9245
diff
changeset
|
685 |
3294 | 686 String comparisons may also be performed with the @code{strcmp} |
687 function, not with the comparison operators listed above. | |
688 @xref{Strings}. | |
689 | |
11403
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
690 @opindex == |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
691 @DOCSTRING(eq) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
692 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
693 @opindex >= |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
694 @DOCSTRING(ge) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
695 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
696 @opindex > |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
697 @DOCSTRING(gt) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
698 |
6550 | 699 @DOCSTRING(isequal) |
700 | |
701 @DOCSTRING(isequalwithequalnans) | |
702 | |
11403
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
703 @opindex <= |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
704 @DOCSTRING(le) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
705 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
706 @opindex < |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
707 @DOCSTRING(lt) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
708 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
709 @opindex != |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
710 @opindex ~= |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
711 @DOCSTRING(ne) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
712 |
4167 | 713 @node Boolean Expressions |
3294 | 714 @section Boolean Expressions |
715 @cindex expressions, boolean | |
716 @cindex boolean expressions | |
717 @cindex expressions, logical | |
718 @cindex logical expressions | |
719 @cindex operators, boolean | |
720 @cindex boolean operators | |
721 @cindex logical operators | |
722 @cindex operators, logical | |
723 @cindex and operator | |
724 @cindex or operator | |
725 @cindex not operator | |
726 | |
727 @menu | |
728 * Element-by-element Boolean Operators:: | |
729 * Short-circuit Boolean Operators:: | |
730 @end menu | |
731 | |
4167 | 732 @node Element-by-element Boolean Operators |
3294 | 733 @subsection Element-by-element Boolean Operators |
734 @cindex element-by-element evaluation | |
735 | |
736 An @dfn{element-by-element boolean expression} is a combination of | |
737 comparison expressions using the boolean | |
738 operators ``or'' (@samp{|}), ``and'' (@samp{&}), and ``not'' (@samp{!}), | |
739 along with parentheses to control nesting. The truth of the boolean | |
740 expression is computed by combining the truth values of the | |
741 corresponding elements of the component expressions. A value is | |
742 considered to be false if it is zero, and true otherwise. | |
743 | |
744 Element-by-element boolean expressions can be used wherever comparison | |
745 expressions can be used. They can be used in @code{if} and @code{while} | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9159
diff
changeset
|
746 statements. However, a matrix value used as the condition in an |
3294 | 747 @code{if} or @code{while} statement is only true if @emph{all} of its |
748 elements are nonzero. | |
749 | |
750 Like comparison operations, each element of an element-by-element | |
751 boolean expression also has a numeric value (1 if true, 0 if false) that | |
752 comes into play if the result of the boolean expression is stored in a | |
753 variable, or used in arithmetic. | |
754 | |
755 Here are descriptions of the three element-by-element boolean operators. | |
756 | |
757 @table @code | |
758 @item @var{boolean1} & @var{boolean2} | |
759 @opindex & | |
760 Elements of the result are true if both corresponding elements of | |
761 @var{boolean1} and @var{boolean2} are true. | |
762 | |
763 @item @var{boolean1} | @var{boolean2} | |
764 @opindex | | |
765 Elements of the result are true if either of the corresponding elements | |
766 of @var{boolean1} or @var{boolean2} is true. | |
767 | |
768 @item ! @var{boolean} | |
769 @itemx ~ @var{boolean} | |
770 @opindex ~ | |
771 @opindex ! | |
772 Each element of the result is true if the corresponding element of | |
773 @var{boolean} is false. | |
774 @end table | |
775 | |
776 For matrix operands, these operators work on an element-by-element | |
777 basis. For example, the expression | |
778 | |
779 @example | |
780 [1, 0; 0, 1] & [1, 0; 2, 3] | |
781 @end example | |
782 | |
783 @noindent | |
784 returns a two by two identity matrix. | |
785 | |
786 For the binary operators, the dimensions of the operands must conform if | |
787 both are matrices. If one of the operands is a scalar and the other a | |
788 matrix, the operator is applied to the scalar and each element of the | |
789 matrix. | |
790 | |
791 For the binary element-by-element boolean operators, both subexpressions | |
792 @var{boolean1} and @var{boolean2} are evaluated before computing the | |
793 result. This can make a difference when the expressions have side | |
794 effects. For example, in the expression | |
795 | |
796 @example | |
797 a & b++ | |
798 @end example | |
799 | |
800 @noindent | |
801 the value of the variable @var{b} is incremented even if the variable | |
802 @var{a} is zero. | |
803 | |
804 This behavior is necessary for the boolean operators to work as | |
805 described for matrix-valued operands. | |
806 | |
11403
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
807 @opindex & |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
808 @DOCSTRING(and) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
809 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
810 @opindex ~ |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
811 @opindex ! |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
812 @DOCSTRING(not) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
813 |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
814 @opindex | |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
815 @DOCSTRING(or) |
b8b08b1ac21f
Add missing operator functions to doc/interpreter.
Judd Storrs <jstorrs@gmail.com>
parents:
10846
diff
changeset
|
816 |
4167 | 817 @node Short-circuit Boolean Operators |
3294 | 818 @subsection Short-circuit Boolean Operators |
819 @cindex short-circuit evaluation | |
820 | |
821 Combined with the implicit conversion to scalar values in @code{if} and | |
822 @code{while} conditions, Octave's element-by-element boolean operators | |
823 are often sufficient for performing most logical operations. However, | |
824 it is sometimes desirable to stop evaluating a boolean expression as | |
825 soon as the overall truth value can be determined. Octave's | |
826 @dfn{short-circuit} boolean operators work this way. | |
827 | |
828 @table @code | |
829 @item @var{boolean1} && @var{boolean2} | |
830 @opindex && | |
831 The expression @var{boolean1} is evaluated and converted to a scalar | |
6632 | 832 using the equivalent of the operation @code{all (@var{boolean1}(:))}. |
3294 | 833 If it is false, the result of the overall expression is 0. If it is |
834 true, the expression @var{boolean2} is evaluated and converted to a | |
6632 | 835 scalar using the equivalent of the operation @code{all |
836 (@var{boolean1}(:))}. If it is true, the result of the overall expression | |
3294 | 837 is 1. Otherwise, the result of the overall expression is 0. |
838 | |
6632 | 839 @strong{Warning:} there is one exception to the rule of evaluating |
840 @code{all (@var{boolean1}(:))}, which is when @code{boolean1} is the | |
9037
4cb9f994dcec
Documentation cleanup of var.texi, expr.texi, eval.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
841 empty matrix. The truth value of an empty matrix is always @code{false} |
6632 | 842 so @code{[] && true} evaluates to @code{false} even though |
843 @code{all ([])} is @code{true}. | |
844 | |
3294 | 845 @item @var{boolean1} || @var{boolean2} |
846 @opindex || | |
847 The expression @var{boolean1} is evaluated and converted to a scalar | |
6632 | 848 using the equivalent of the operation @code{all (@var{boolean1}(:))}. |
3294 | 849 If it is true, the result of the overall expression is 1. If it is |
850 false, the expression @var{boolean2} is evaluated and converted to a | |
6632 | 851 scalar using the equivalent of the operation @code{all |
852 (@var{boolean1}(:))}. If it is true, the result of the overall expression | |
3294 | 853 is 1. Otherwise, the result of the overall expression is 0. |
6632 | 854 |
855 @strong{Warning:} the truth value of an empty matrix is always @code{false}, | |
856 see the previous list item for details. | |
3294 | 857 @end table |
858 | |
859 The fact that both operands may not be evaluated before determining the | |
860 overall truth value of the expression can be important. For example, in | |
861 the expression | |
862 | |
863 @example | |
864 a && b++ | |
865 @end example | |
866 | |
867 @noindent | |
868 the value of the variable @var{b} is only incremented if the variable | |
869 @var{a} is nonzero. | |
870 | |
871 This can be used to write somewhat more concise code. For example, it | |
872 is possible write | |
873 | |
874 @example | |
875 @group | |
876 function f (a, b, c) | |
7768
a2d9f325b65a
Use isschar instead of deprecated isstr
Rafael Laboissiere <rafael@debian.org>
parents:
7594
diff
changeset
|
877 if (nargin > 2 && ischar (c)) |
3294 | 878 @dots{} |
879 @end group | |
880 @end example | |
881 | |
882 @noindent | |
883 instead of having to use two @code{if} statements to avoid attempting to | |
884 evaluate an argument that doesn't exist. For example, without the | |
885 short-circuit feature, it would be necessary to write | |
886 | |
887 @example | |
888 @group | |
889 function f (a, b, c) | |
890 if (nargin > 2) | |
7768
a2d9f325b65a
Use isschar instead of deprecated isstr
Rafael Laboissiere <rafael@debian.org>
parents:
7594
diff
changeset
|
891 if (ischar (c)) |
3294 | 892 @dots{} |
893 @end group | |
894 @end example | |
895 | |
6632 | 896 @noindent |
3294 | 897 Writing |
898 | |
899 @example | |
900 @group | |
901 function f (a, b, c) | |
7768
a2d9f325b65a
Use isschar instead of deprecated isstr
Rafael Laboissiere <rafael@debian.org>
parents:
7594
diff
changeset
|
902 if (nargin > 2 & ischar (c)) |
3294 | 903 @dots{} |
904 @end group | |
905 @end example | |
906 | |
907 @noindent | |
908 would result in an error if @code{f} were called with one or two | |
909 arguments because Octave would be forced to try to evaluate both of the | |
910 operands for the operator @samp{&}. | |
911 | |
12543
f60f755ebfe4
Add do_braindead_shortcircuit_evaluation to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11552
diff
changeset
|
912 @sc{matlab} has special behavior that allows the operators @samp{&} and |
f60f755ebfe4
Add do_braindead_shortcircuit_evaluation to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11552
diff
changeset
|
913 @samp{|} to short-circuit when used in the truth expression for @code{if} and |
f60f755ebfe4
Add do_braindead_shortcircuit_evaluation to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11552
diff
changeset
|
914 @code{while} statements. The Octave parser may be instructed to behave in the |
12601
99babbf683ff
doc: Correct use of it's -> its in documentation.
Rik <octave@nomad.inbox5.com>
parents:
12546
diff
changeset
|
915 same manner, but its use is strongly discouraged. |
12543
f60f755ebfe4
Add do_braindead_shortcircuit_evaluation to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11552
diff
changeset
|
916 |
f60f755ebfe4
Add do_braindead_shortcircuit_evaluation to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11552
diff
changeset
|
917 @DOCSTRING(do_braindead_shortcircuit_evaluation) |
f60f755ebfe4
Add do_braindead_shortcircuit_evaluation to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11552
diff
changeset
|
918 |
f60f755ebfe4
Add do_braindead_shortcircuit_evaluation to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11552
diff
changeset
|
919 Finally, the ternary operator (?:) is not supported in Octave. If |
f60f755ebfe4
Add do_braindead_shortcircuit_evaluation to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11552
diff
changeset
|
920 short-circuiting is not important, it can be replaced by the @code{ifelse} |
f60f755ebfe4
Add do_braindead_shortcircuit_evaluation to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11552
diff
changeset
|
921 function. |
10308 | 922 |
11552
6b6e9051ecb8
Add merge/ifelse function to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
923 @DOCSTRING(merge) |
10308 | 924 |
4167 | 925 @node Assignment Ops |
3294 | 926 @section Assignment Expressions |
927 @cindex assignment expressions | |
928 @cindex assignment operators | |
929 @cindex operators, assignment | |
930 @cindex expressions, assignment | |
931 | |
932 @opindex = | |
933 | |
934 An @dfn{assignment} is an expression that stores a new value into a | |
935 variable. For example, the following expression assigns the value 1 to | |
936 the variable @code{z}: | |
937 | |
938 @example | |
939 z = 1 | |
940 @end example | |
941 | |
6632 | 942 @noindent |
3294 | 943 After this expression is executed, the variable @code{z} has the value 1. |
944 Whatever old value @code{z} had before the assignment is forgotten. | |
945 The @samp{=} sign is called an @dfn{assignment operator}. | |
946 | |
947 Assignments can store string values also. For example, the following | |
948 expression would store the value @code{"this food is good"} in the | |
949 variable @code{message}: | |
950 | |
951 @example | |
952 @group | |
953 thing = "food" | |
954 predicate = "good" | |
955 message = [ "this " , thing , " is " , predicate ] | |
956 @end group | |
957 @end example | |
958 | |
959 @noindent | |
960 (This also illustrates concatenation of strings.) | |
961 | |
962 @cindex side effect | |
963 Most operators (addition, concatenation, and so on) have no effect | |
964 except to compute a value. If you ignore the value, you might as well | |
965 not use the operator. An assignment operator is different. It does | |
966 produce a value, but even if you ignore the value, the assignment still | |
967 makes itself felt through the alteration of the variable. We call this | |
968 a @dfn{side effect}. | |
969 | |
970 @cindex lvalue | |
971 The left-hand operand of an assignment need not be a variable | |
972 (@pxref{Variables}). It can also be an element of a matrix | |
973 (@pxref{Index Expressions}) or a list of return values | |
974 (@pxref{Calling Functions}). These are all called @dfn{lvalues}, which | |
975 means they can appear on the left-hand side of an assignment operator. | |
976 The right-hand operand may be any expression. It produces the new value | |
977 which the assignment stores in the specified variable, matrix element, | |
978 or list of return values. | |
979 | |
980 It is important to note that variables do @emph{not} have permanent types. | |
981 The type of a variable is simply the type of whatever value it happens | |
982 to hold at the moment. In the following program fragment, the variable | |
983 @code{foo} has a numeric value at first, and a string value later on: | |
984 | |
985 @example | |
986 @group | |
987 octave:13> foo = 1 | |
988 foo = 1 | |
989 octave:13> foo = "bar" | |
990 foo = bar | |
991 @end group | |
992 @end example | |
993 | |
994 @noindent | |
995 When the second assignment gives @code{foo} a string value, the fact that | |
996 it previously had a numeric value is forgotten. | |
997 | |
998 Assignment of a scalar to an indexed matrix sets all of the elements | |
999 that are referenced by the indices to the scalar value. For example, if | |
1000 @code{a} is a matrix with at least two columns, | |
1001 | |
1002 @example | |
1003 @group | |
1004 a(:, 2) = 5 | |
1005 @end group | |
1006 @end example | |
1007 | |
1008 @noindent | |
1009 sets all the elements in the second column of @code{a} to 5. | |
1010 | |
1011 Assigning an empty matrix @samp{[]} works in most cases to allow you to | |
1012 delete rows or columns of matrices and vectors. @xref{Empty Matrices}. | |
1013 For example, given a 4 by 5 matrix @var{A}, the assignment | |
1014 | |
1015 @example | |
1016 A (3, :) = [] | |
1017 @end example | |
1018 | |
1019 @noindent | |
1020 deletes the third row of @var{A}, and the assignment | |
1021 | |
1022 @example | |
1023 A (:, 1:2:5) = [] | |
1024 @end example | |
1025 | |
1026 @noindent | |
6672 | 1027 deletes the first, third, and fifth columns. |
3294 | 1028 |
1029 An assignment is an expression, so it has a value. Thus, @code{z = 1} | |
1030 as an expression has the value 1. One consequence of this is that you | |
1031 can write multiple assignments together: | |
1032 | |
1033 @example | |
1034 x = y = z = 0 | |
1035 @end example | |
1036 | |
1037 @noindent | |
1038 stores the value 0 in all three variables. It does this because the | |
1039 value of @code{z = 0}, which is 0, is stored into @code{y}, and then | |
1040 the value of @code{y = z = 0}, which is 0, is stored into @code{x}. | |
1041 | |
1042 This is also true of assignments to lists of values, so the following is | |
1043 a valid expression | |
1044 | |
1045 @example | |
1046 [a, b, c] = [u, s, v] = svd (a) | |
1047 @end example | |
1048 | |
1049 @noindent | |
1050 that is exactly equivalent to | |
1051 | |
1052 @example | |
1053 @group | |
1054 [u, s, v] = svd (a) | |
1055 a = u | |
1056 b = s | |
1057 c = v | |
1058 @end group | |
1059 @end example | |
1060 | |
1061 In expressions like this, the number of values in each part of the | |
1062 expression need not match. For example, the expression | |
1063 | |
1064 @example | |
1065 [a, b] = [u, s, v] = svd (a) | |
1066 @end example | |
1067 | |
1068 @noindent | |
1069 is equivalent to | |
1070 | |
1071 @example | |
1072 @group | |
1073 [u, s, v] = svd (a) | |
1074 a = u | |
1075 b = s | |
1076 @end group | |
1077 @end example | |
1078 | |
6632 | 1079 @noindent |
1080 The number of values on the left side of the expression can, however, | |
9037
4cb9f994dcec
Documentation cleanup of var.texi, expr.texi, eval.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
1081 not exceed the number of values on the right side. For example, the |
6632 | 1082 following will produce an error. |
1083 | |
9153
5247e89688e1
Eliminate most overfull errors when running texi2pdf for generating pdf documentation
Rik <rdrider0-list@yahoo.com>
parents:
9037
diff
changeset
|
1084 @example |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9159
diff
changeset
|
1085 @group |
8015
30629059b72d
Update the manual to reflect the changes in error output
sh@sh-laptop
parents:
7768
diff
changeset
|
1086 [a, b, c, d] = [u, s, v] = svd (a); |
7031 | 1087 @print{} error: element number 4 undefined in return list |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9159
diff
changeset
|
1088 @end group |
9153
5247e89688e1
Eliminate most overfull errors when running texi2pdf for generating pdf documentation
Rik <rdrider0-list@yahoo.com>
parents:
9037
diff
changeset
|
1089 @end example |
6632 | 1090 |
10209
ea0d83b4470b
document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents:
9758
diff
changeset
|
1091 The symbol @code{~} may be used as a placeholder in the list of lvalues, |
ea0d83b4470b
document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents:
9758
diff
changeset
|
1092 indicating that the corresponding return value should be ignored and not stored |
ea0d83b4470b
document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents:
9758
diff
changeset
|
1093 anywhere: |
ea0d83b4470b
document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents:
9758
diff
changeset
|
1094 |
ea0d83b4470b
document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents:
9758
diff
changeset
|
1095 @example |
ea0d83b4470b
document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents:
9758
diff
changeset
|
1096 @group |
ea0d83b4470b
document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents:
9758
diff
changeset
|
1097 [~, s, v] = svd (a); |
ea0d83b4470b
document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents:
9758
diff
changeset
|
1098 @end group |
ea0d83b4470b
document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents:
9758
diff
changeset
|
1099 @end example |
ea0d83b4470b
document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents:
9758
diff
changeset
|
1100 |
10228 | 1101 This is cleaner and more memory efficient than using a dummy variable. |
1102 The @code{nargout} value for the right-hand side expression is not affected. | |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10711
diff
changeset
|
1103 If the assignment is used as an expression, the return value is a |
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10711
diff
changeset
|
1104 comma-separated list with the ignored values dropped. |
10209
ea0d83b4470b
document use of ~ placeholders in the manual
Jaroslav Hajek <highegg@gmail.com>
parents:
9758
diff
changeset
|
1105 |
6642 | 1106 @opindex += |
1107 A very common programming pattern is to increment an existing variable | |
1108 with a given value, like this | |
1109 | |
1110 @example | |
1111 a = a + 2; | |
1112 @end example | |
1113 | |
1114 @noindent | |
1115 This can be written in a clearer and more condensed form using the | |
1116 @code{+=} operator | |
1117 | |
1118 @example | |
1119 a += 2; | |
1120 @end example | |
1121 | |
1122 @noindent | |
1123 @opindex -= | |
1124 @opindex *= | |
1125 @opindex /= | |
1126 Similar operators also exist for subtraction (@code{-=}), | |
9037
4cb9f994dcec
Documentation cleanup of var.texi, expr.texi, eval.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
1127 multiplication (@code{*=}), and division (@code{/=}). An expression |
6642 | 1128 of the form |
1129 | |
1130 @example | |
1131 @var{expr1} @var{op}= @var{expr2} | |
1132 @end example | |
1133 | |
1134 @noindent | |
1135 is evaluated as | |
1136 | |
1137 @example | |
1138 @var{expr1} = (@var{expr1}) @var{op} (@var{expr2}) | |
1139 @end example | |
1140 | |
1141 @noindent | |
1142 where @var{op} can be either @code{+}, @code{-}, @code{*}, or @code{/}. | |
1143 So, the expression | |
1144 | |
1145 @example | |
1146 a *= b+1 | |
1147 @end example | |
1148 | |
1149 @noindent | |
1150 is evaluated as | |
1151 | |
1152 @example | |
1153 a = a * (b+1) | |
1154 @end example | |
1155 | |
1156 @noindent | |
1157 and @emph{not} | |
1158 | |
1159 @example | |
1160 a = a * b + 1 | |
1161 @end example | |
1162 | |
3294 | 1163 You can use an assignment anywhere an expression is called for. For |
1164 example, it is valid to write @code{x != (y = 1)} to set @code{y} to 1 | |
1165 and then test whether @code{x} equals 1. But this style tends to make | |
1166 programs hard to read. Except in a one-shot program, you should rewrite | |
1167 it to get rid of such nesting of assignments. This is never very hard. | |
1168 | |
1169 @cindex increment operator | |
1170 @cindex decrement operator | |
1171 @cindex operators, increment | |
1172 @cindex operators, decrement | |
1173 | |
4167 | 1174 @node Increment Ops |
3294 | 1175 @section Increment Operators |
1176 | |
1177 @emph{Increment operators} increase or decrease the value of a variable | |
1178 by 1. The operator to increment a variable is written as @samp{++}. It | |
1179 may be used to increment a variable either before or after taking its | |
1180 value. | |
1181 | |
1182 For example, to pre-increment the variable @var{x}, you would write | |
1183 @code{++@var{x}}. This would add one to @var{x} and then return the new | |
1184 value of @var{x} as the result of the expression. It is exactly the | |
1185 same as the expression @code{@var{x} = @var{x} + 1}. | |
1186 | |
1187 To post-increment a variable @var{x}, you would write @code{@var{x}++}. | |
1188 This adds one to the variable @var{x}, but returns the value that | |
1189 @var{x} had prior to incrementing it. For example, if @var{x} is equal | |
1190 to 2, the result of the expression @code{@var{x}++} is 2, and the new | |
1191 value of @var{x} is 3. | |
1192 | |
1193 For matrix and vector arguments, the increment and decrement operators | |
1194 work on each element of the operand. | |
1195 | |
1196 Here is a list of all the increment and decrement expressions. | |
1197 | |
1198 @table @code | |
1199 @item ++@var{x} | |
1200 @opindex ++ | |
1201 This expression increments the variable @var{x}. The value of the | |
1202 expression is the @emph{new} value of @var{x}. It is equivalent to the | |
1203 expression @code{@var{x} = @var{x} + 1}. | |
1204 | |
1205 @item --@var{x} | |
1206 @opindex @code{--} | |
1207 This expression decrements the variable @var{x}. The value of the | |
1208 expression is the @emph{new} value of @var{x}. It is equivalent to the | |
1209 expression @code{@var{x} = @var{x} - 1}. | |
1210 | |
1211 @item @var{x}++ | |
1212 @opindex ++ | |
1213 This expression causes the variable @var{x} to be incremented. The | |
1214 value of the expression is the @emph{old} value of @var{x}. | |
1215 | |
1216 @item @var{x}-- | |
1217 @opindex @code{--} | |
1218 This expression causes the variable @var{x} to be decremented. The | |
1219 value of the expression is the @emph{old} value of @var{x}. | |
1220 @end table | |
1221 | |
4167 | 1222 @node Operator Precedence |
3294 | 1223 @section Operator Precedence |
1224 @cindex operator precedence | |
1225 | |
1226 @dfn{Operator precedence} determines how operators are grouped, when | |
1227 different operators appear close by in one expression. For example, | |
1228 @samp{*} has higher precedence than @samp{+}. Thus, the expression | |
1229 @code{a + b * c} means to multiply @code{b} and @code{c}, and then add | |
1230 @code{a} to the product (i.e., @code{a + (b * c)}). | |
1231 | |
1232 You can overrule the precedence of the operators by using parentheses. | |
1233 You can think of the precedence rules as saying where the parentheses | |
1234 are assumed if you do not write parentheses yourself. In fact, it is | |
1235 wise to use parentheses whenever you have an unusual combination of | |
1236 operators, because other people who read the program may not remember | |
1237 what the precedence is in this case. You might forget as well, and then | |
1238 you too could make a mistake. Explicit parentheses will help prevent | |
1239 any such mistake. | |
1240 | |
1241 When operators of equal precedence are used together, the leftmost | |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1242 operator groups first, except for the assignment operators, which group |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1243 in the opposite order. Thus, the expression @code{a - b + c} groups as |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1244 @code{(a - b) + c}, but the expression @code{a = b = c} groups as |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1245 @code{a = (b = c)}. |
3294 | 1246 |
1247 The precedence of prefix unary operators is important when another | |
1248 operator follows the operand. For example, @code{-x^2} means | |
1249 @code{-(x^2)}, because @samp{-} has lower precedence than @samp{^}. | |
1250 | |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1251 Here is a table of the operators in Octave, in order of decreasing |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1252 precedence. Unless noted, all operators group left to right. |
3294 | 1253 |
1254 @table @code | |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1255 @item function call and array indexing, cell array indexing, and structure element indexing |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1256 @samp{()} @samp{@{@}} @samp{.} |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1257 |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1258 @item postfix increment, and postfix decrement |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1259 @samp{++} @samp{--} |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1260 |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1261 These operators group right to left. |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1262 |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1263 @item transpose and exponentiation |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1264 @samp{'} @samp{.'} @samp{^} @samp{**} @samp{.^} @samp{.**} |
3294 | 1265 |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1266 @item unary plus, unary minus, prefix increment, prefix decrement, and logical "not" |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1267 @samp{+} @samp{-} @samp{++} @samp{--} @samp{~} @samp{!} |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1268 |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1269 @item multiply and divide |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1270 @samp{*} @samp{/} @samp{\} @samp{.\} @samp{.*} @samp{./} |
3294 | 1271 |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1272 @item add, subtract |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1273 @samp{+} @samp{-} |
3294 | 1274 |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1275 @item colon |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1276 @samp{:} |
3294 | 1277 |
1278 @item relational | |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1279 @samp{<} @samp{<=} @samp{==} @samp{>=} @samp{>} @samp{!=} |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1280 @samp{~=} |
3294 | 1281 |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1282 @item element-wise "and" |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1283 @samp{&} |
3294 | 1284 |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1285 @item element-wise "or" |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1286 @samp{|} |
3294 | 1287 |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1288 @item logical "and" |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1289 @samp{&&} |
3294 | 1290 |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1291 @item logical "or" |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1292 @samp{||} |
3294 | 1293 |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1294 @item assignment |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1295 @samp{=} @samp{+=} @samp{-=} @samp{*=} @samp{/=} @samp{\=} |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1296 @samp{^=} @samp{.*=} @samp{./=} @samp{.\=} @samp{.^=} @samp{|=} |
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1297 @samp{&=} |
3294 | 1298 |
12627
002948ae5bc0
fix precedence level of transpose operators (bug #32533)
John W. Eaton <jwe@octave.org>
parents:
12601
diff
changeset
|
1299 These operators group right to left. |
3294 | 1300 @end table |