Mercurial > hg > octave-lyh
annotate scripts/miscellaneous/xor.m @ 11472:1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sun, 09 Jan 2011 21:33:04 -0800 |
parents | 8db5553c24f5 |
children | fd0a3ac60b0e |
rev | line source |
---|---|
8920 | 1 ## Copyright (C) 1995, 1996, 1997, 1999, 2000, 2002, 2005, 2006, 2007, 2008 |
7017 | 2 ## Kurt Hornik |
3426 | 3 ## |
3922 | 4 ## This file is part of Octave. |
5 ## | |
6 ## Octave is free software; you can redistribute it and/or modify it | |
7 ## under the terms of the GNU General Public License as published by | |
7016 | 8 ## the Free Software Foundation; either version 3 of the License, or (at |
9 ## your option) any later version. | |
3426 | 10 ## |
3922 | 11 ## Octave is distributed in the hope that it will be useful, but |
2538 | 12 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
3426 | 14 ## General Public License for more details. |
15 ## | |
2538 | 16 ## You should have received a copy of the GNU General Public License |
7016 | 17 ## along with Octave; see the file COPYING. If not, see |
18 ## <http://www.gnu.org/licenses/>. | |
2538 | 19 |
3321 | 20 ## -*- texinfo -*- |
21 ## @deftypefn {Mapping Function} {} xor (@var{x}, @var{y}) | |
22 ## Return the `exclusive or' of the entries of @var{x} and @var{y}. | |
23 ## For boolean expressions @var{x} and @var{y}, | |
24 ## @code{xor (@var{x}, @var{y})} is true if and only if @var{x} or @var{y} | |
25 ## is true, but not if both @var{x} and @var{y} are true. | |
26 ## @end deftypefn | |
2538 | 27 |
5428 | 28 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
2538 | 29 ## Created: 16 September 1994 |
30 ## Adapted-By: jwe | |
31 | |
32 function z = xor (x, y) | |
33 | |
2621 | 34 if (nargin == 2) |
6157 | 35 if (isscalar (x) || isscalar (y) || size_equal (x, y)) |
10031 | 36 ## Typecast to logicals is necessary for other numeric types. |
37 z = logical (x) != logical (y); | |
2621 | 38 else |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
10031
diff
changeset
|
39 error ("xor: X and Y must be of common size or scalars"); |
2621 | 40 endif |
41 else | |
6046 | 42 print_usage (); |
2538 | 43 endif |
44 | |
45 endfunction | |
7385 | 46 |
47 %!assert((xor ([1, 1, 0, 0], [0, 1, 0, 1]) == [1, 0, 0, 1] | |
48 %! && xor ([i, i, 0, 0], [1, 0, 1, 0]) == [0, 1, 1, 0])); | |
49 | |
50 %!assert(all (all (xor (eye (2), fliplr (eye (2))) == ones (2)))); | |
51 | |
52 %!error xor (); | |
53 | |
54 %!error xor (1, 2, 3); | |
55 |