changeset 13287:5c22edebf2e8

rot90.m: Simplify function by using mod() rather than rem() * rot90.m: Simplify function by using mod() rather than rem()
author Rik <octave@nomad.inbox5.com>
date Fri, 07 Oct 2011 08:39:00 -0700
parents 49ae6f497171
children 497bb1cf7b15
files scripts/general/rot90.m
diffstat 1 files changed, 8 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/general/rot90.m	Fri Oct 07 08:28:00 2011 -0700
+++ b/scripts/general/rot90.m	Fri Oct 07 08:39:00 2011 -0700
@@ -60,17 +60,11 @@
 
   if (ndims (A) > 2)
     error ("rot90: A must be a 2-D array");
-  endif
-
-  if (! (isscalar (k) && isreal (k) && fix (k) == k))
+  elseif (! (isscalar (k) && isreal (k) && k == fix (k)))
     error ("rot90: K must be a single real integer");
   endif
 
-  k = rem (k, 4);
-
-  if (k < 0)
-    k = k + 4;
-  endif
+  k = mod (k, 4);
 
   if (k == 0)
     B = A;
@@ -93,12 +87,12 @@
 %! x3 = [4, 3; 2, 1];
 %! x4 = [3, 1; 4, 2];
 %!
-%! assert(rot90 (x1) == x2);
-%! assert(rot90 (x1, 2) == x3);
-%! assert(rot90 (x1, 3) == x4);
-%! assert(rot90 (x1, 4) == x1);
-%! assert(rot90 (x1, 5) == x2);
-%! assert(rot90 (x1, -1) == x4);
+%! assert(rot90 (x1), x2);
+%! assert(rot90 (x1, 2), x3);
+%! assert(rot90 (x1, 3), x4);
+%! assert(rot90 (x1, 4), x1);
+%! assert(rot90 (x1, 5), x2);
+%! assert(rot90 (x1, -1), x4);
 
 %% Test input validation
 %!error rot90 ();