changeset 10031:8db5553c24f5

optimize xor
author Jaroslav Hajek <highegg@gmail.com>
date Sat, 26 Dec 2009 21:30:15 +0100
parents 83bb2a78c07d
children 691b4ba32425
files scripts/ChangeLog scripts/miscellaneous/xor.m
diffstat 2 files changed, 6 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog	Sat Dec 26 14:07:50 2009 +0100
+++ b/scripts/ChangeLog	Sat Dec 26 21:30:15 2009 +0100
@@ -1,3 +1,7 @@
+2009-12-26  Jaroslav Hajek  <highegg@gmail.com>
+
+	* miscellaneous/xor.m: Optimize.
+
 2009-12-25  Jaroslav Hajek  <highegg@gmail.com>
 
 	* general/issquare.m: Do not check type.
--- a/scripts/miscellaneous/xor.m	Sat Dec 26 14:07:50 2009 +0100
+++ b/scripts/miscellaneous/xor.m	Sat Dec 26 21:30:15 2009 +0100
@@ -33,7 +33,8 @@
 
   if (nargin == 2)
     if (isscalar (x) || isscalar (y) || size_equal (x, y))
-      z = logical ((x | y) - (x & y));
+      ## Typecast to logicals is necessary for other numeric types.
+      z = logical (x) != logical (y);
     else
       error ("xor: x and y must be of common size or scalars");
     endif