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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8920
eb63fbe60fab update copyright notices
John W. Eaton <jwe@octave.org>
parents: 7385
diff changeset
1 ## Copyright (C) 1995, 1996, 1997, 1999, 2000, 2002, 2005, 2006, 2007, 2008
7017
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
2 ## Kurt Hornik
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3321
diff changeset
3 ##
3922
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3426
diff changeset
4 ## This file is part of Octave.
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3426
diff changeset
5 ##
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3426
diff changeset
6 ## Octave is free software; you can redistribute it and/or modify it
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3426
diff changeset
7 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6157
diff changeset
8 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6157
diff changeset
9 ## your option) any later version.
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3321
diff changeset
10 ##
3922
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3426
diff changeset
11 ## Octave is distributed in the hope that it will be useful, but
2538
6f71af650490 [project @ 1996-11-19 21:41:48 by jwe]
jwe
parents:
diff changeset
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of
6f71af650490 [project @ 1996-11-19 21:41:48 by jwe]
jwe
parents:
diff changeset
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3321
diff changeset
14 ## General Public License for more details.
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3321
diff changeset
15 ##
2538
6f71af650490 [project @ 1996-11-19 21:41:48 by jwe]
jwe
parents:
diff changeset
16 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6157
diff changeset
17 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6157
diff changeset
18 ## <http://www.gnu.org/licenses/>.
2538
6f71af650490 [project @ 1996-11-19 21:41:48 by jwe]
jwe
parents:
diff changeset
19
3321
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 2870
diff changeset
20 ## -*- texinfo -*-
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 2870
diff changeset
21 ## @deftypefn {Mapping Function} {} xor (@var{x}, @var{y})
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 2870
diff changeset
22 ## Return the `exclusive or' of the entries of @var{x} and @var{y}.
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 2870
diff changeset
23 ## For boolean expressions @var{x} and @var{y},
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 2870
diff changeset
24 ## @code{xor (@var{x}, @var{y})} is true if and only if @var{x} or @var{y}
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 2870
diff changeset
25 ## is true, but not if both @var{x} and @var{y} are true.
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 2870
diff changeset
26 ## @end deftypefn
2538
6f71af650490 [project @ 1996-11-19 21:41:48 by jwe]
jwe
parents:
diff changeset
27
5428
2a16423e4aa0 [project @ 2005-08-23 18:38:27 by jwe]
jwe
parents: 5307
diff changeset
28 ## Author: KH <Kurt.Hornik@wu-wien.ac.at>
2538
6f71af650490 [project @ 1996-11-19 21:41:48 by jwe]
jwe
parents:
diff changeset
29 ## Created: 16 September 1994
6f71af650490 [project @ 1996-11-19 21:41:48 by jwe]
jwe
parents:
diff changeset
30 ## Adapted-By: jwe
6f71af650490 [project @ 1996-11-19 21:41:48 by jwe]
jwe
parents:
diff changeset
31
6f71af650490 [project @ 1996-11-19 21:41:48 by jwe]
jwe
parents:
diff changeset
32 function z = xor (x, y)
6f71af650490 [project @ 1996-11-19 21:41:48 by jwe]
jwe
parents:
diff changeset
33
2621
337a09dd1c06 [project @ 1997-01-24 21:49:41 by jwe]
jwe
parents: 2538
diff changeset
34 if (nargin == 2)
6157
045038e0108a [project @ 2006-11-13 22:22:53 by jwe]
jwe
parents: 6046
diff changeset
35 if (isscalar (x) || isscalar (y) || size_equal (x, y))
10031
8db5553c24f5 optimize xor
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
36 ## Typecast to logicals is necessary for other numeric types.
8db5553c24f5 optimize xor
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
37 z = logical (x) != logical (y);
2621
337a09dd1c06 [project @ 1997-01-24 21:49:41 by jwe]
jwe
parents: 2538
diff changeset
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
337a09dd1c06 [project @ 1997-01-24 21:49:41 by jwe]
jwe
parents: 2538
diff changeset
40 endif
337a09dd1c06 [project @ 1997-01-24 21:49:41 by jwe]
jwe
parents: 2538
diff changeset
41 else
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5428
diff changeset
42 print_usage ();
2538
6f71af650490 [project @ 1996-11-19 21:41:48 by jwe]
jwe
parents:
diff changeset
43 endif
6f71af650490 [project @ 1996-11-19 21:41:48 by jwe]
jwe
parents:
diff changeset
44
6f71af650490 [project @ 1996-11-19 21:41:48 by jwe]
jwe
parents:
diff changeset
45 endfunction
7385
8b7b4f58199f [project @ 2008-01-15 20:49:09 by jwe]
jwe
parents: 7017
diff changeset
46
8b7b4f58199f [project @ 2008-01-15 20:49:09 by jwe]
jwe
parents: 7017
diff changeset
47 %!assert((xor ([1, 1, 0, 0], [0, 1, 0, 1]) == [1, 0, 0, 1]
8b7b4f58199f [project @ 2008-01-15 20:49:09 by jwe]
jwe
parents: 7017
diff changeset
48 %! && xor ([i, i, 0, 0], [1, 0, 1, 0]) == [0, 1, 1, 0]));
8b7b4f58199f [project @ 2008-01-15 20:49:09 by jwe]
jwe
parents: 7017
diff changeset
49
8b7b4f58199f [project @ 2008-01-15 20:49:09 by jwe]
jwe
parents: 7017
diff changeset
50 %!assert(all (all (xor (eye (2), fliplr (eye (2))) == ones (2))));
8b7b4f58199f [project @ 2008-01-15 20:49:09 by jwe]
jwe
parents: 7017
diff changeset
51
8b7b4f58199f [project @ 2008-01-15 20:49:09 by jwe]
jwe
parents: 7017
diff changeset
52 %!error xor ();
8b7b4f58199f [project @ 2008-01-15 20:49:09 by jwe]
jwe
parents: 7017
diff changeset
53
8b7b4f58199f [project @ 2008-01-15 20:49:09 by jwe]
jwe
parents: 7017
diff changeset
54 %!error xor (1, 2, 3);
8b7b4f58199f [project @ 2008-01-15 20:49:09 by jwe]
jwe
parents: 7017
diff changeset
55