Mercurial > hg > octave-lyh
annotate scripts/miscellaneous/xor.m @ 16207:0467d68ca891
move current_input_line to lexical_feedback class
* input.h, input.cc, lex.h, lex.ll (current_input_line): Declare as
member of lexical_feedback class.
(octave_base_reader::octave_gets, octave_terminal_reader::get_input,
octave_file_reader::get_input, octave_eval_string_reader::get_input):
Don't set current_input_line.
(octave_lexer::read): Set current_input_line.
* oct-parse.in.yy (octave_parser::bison_error): Use
curr_lexer->current_input_line.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 06 Mar 2013 19:39:48 -0500 |
parents | f3d52523cde1 |
children | 7268845c0a1e |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
13006
diff
changeset
|
1 ## Copyright (C) 1995-2012 Kurt Hornik |
3426 | 2 ## |
3922 | 3 ## This file is part of Octave. |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
3426 | 9 ## |
3922 | 10 ## Octave is distributed in the hope that it will be useful, but |
2538 | 11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
3426 | 13 ## General Public License for more details. |
14 ## | |
2538 | 15 ## You should have received a copy of the GNU General Public License |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
2538 | 18 |
3321 | 19 ## -*- texinfo -*- |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
20 ## @deftypefn {Mapping Function} {@var{z} =} xor (@var{x}, @var{y}) |
3321 | 21 ## Return the `exclusive or' of the entries of @var{x} and @var{y}. |
22 ## For boolean expressions @var{x} and @var{y}, | |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
23 ## @code{xor (@var{x}, @var{y})} is true if and only if one of @var{x} or |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
24 ## @var{y} is true. Otherwise, for @var{x} and @var{y} both true or both |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
25 ## false, @code{xor} returns false. |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
26 ## |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
27 ## The truth table for the xor operation is |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
28 ## |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
29 ## @multitable @columnfractions 0.44 .03 .05 .03 0.44 |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
30 ## @item @tab @var{x} @tab @var{y} @tab @var{z} @tab |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
31 ## @item @tab 0 @tab 0 @tab 0 @tab |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
32 ## @item @tab 1 @tab 0 @tab 1 @tab |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
33 ## @item @tab 0 @tab 1 @tab 1 @tab |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
34 ## @item @tab 1 @tab 1 @tab 0 @tab |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
35 ## @end multitable |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
36 ## |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
37 ## @seealso{and, or, not} |
3321 | 38 ## @end deftypefn |
2538 | 39 |
5428 | 40 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
2538 | 41 ## Created: 16 September 1994 |
42 ## Adapted-By: jwe | |
43 | |
44 function z = xor (x, y) | |
45 | |
2621 | 46 if (nargin == 2) |
6157 | 47 if (isscalar (x) || isscalar (y) || size_equal (x, y)) |
10031 | 48 ## Typecast to logicals is necessary for other numeric types. |
49 z = logical (x) != logical (y); | |
2621 | 50 else |
13006
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12639
diff
changeset
|
51 try |
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12639
diff
changeset
|
52 z = bsxfun (@xor, x, y); |
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12639
diff
changeset
|
53 catch |
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12639
diff
changeset
|
54 error ("xor: X and Y must be of compatible size or scalars"); |
61be447052c3
Implement automatic bsxfun almost everywhere now except sparse matrices.
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12639
diff
changeset
|
55 end_try_catch |
2621 | 56 endif |
57 else | |
6046 | 58 print_usage (); |
2538 | 59 endif |
60 | |
61 endfunction | |
7385 | 62 |
63 | |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
64 %!assert (xor ([1, 1, 0, 0], [0, 1, 0, 1]), logical ([1, 0, 0, 1])) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
65 %!assert (xor ([i, i, 0, 0], [1, 0, 1, 0]), logical ([0, 1, 1, 0])) |
7385 | 66 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
67 %!assert (xor (eye (2), fliplr (eye (2))), logical (ones (2))) |
7385 | 68 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
69 %!error xor () |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
70 %!error xor (1, 2, 3) |
7385 | 71 |