changeset 13279:984359717d71

Use common code idiom for checking whether a double value is an integer. * num2str.m, rotdim.m, get_first_help_sentence.m, ind2rgb.m, commutation_matrix.m, figure.m, legend.m, polyfit.m, bartlett.m, blackman.m, detrend.m, hamming.m, hanning.m, factorial.m, mode.m, skewness.m, statistics.m, mcnemar_test.m: Use idiom 'x == fix (x)' to test for integerness.
author Rik <octave@nomad.inbox5.com>
date Wed, 05 Oct 2011 13:10:10 -0700
parents 04edb15d7966
children c60a059a18bc
files scripts/general/num2str.m scripts/general/rotdim.m scripts/help/get_first_help_sentence.m scripts/image/ind2rgb.m scripts/linear-algebra/commutation_matrix.m scripts/plot/figure.m scripts/plot/legend.m scripts/polynomial/polyfit.m scripts/signal/bartlett.m scripts/signal/blackman.m scripts/signal/detrend.m scripts/signal/hamming.m scripts/signal/hanning.m scripts/specfun/factorial.m scripts/statistics/base/mode.m scripts/statistics/base/skewness.m scripts/statistics/base/statistics.m scripts/statistics/tests/mcnemar_test.m
diffstat 18 files changed, 24 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/general/num2str.m	Wed Oct 05 12:00:31 2011 -0700
+++ b/scripts/general/num2str.m	Wed Oct 05 13:10:10 2011 -0700
@@ -75,7 +75,7 @@
       if (ischar (arg))
         fmt = cstrcat (arg, "%-+", arg(2:end), "i");
       else
-        if (isnumeric (x) && round (x) == x && abs (x) < (10 .^ arg))
+        if (isnumeric (x) && x == fix (x) && abs (x) < (10 .^ arg))
           fmt = sprintf ("%%%dd%%-+%ddi  ", arg, arg);
         else
           fmt = sprintf ("%%%d.%dg%%-+%d.%dgi", arg+7, arg, arg+7, arg);
@@ -83,7 +83,7 @@
       endif
     else
       ## Setup a suitable format string
-      if (isnumeric (x) && round (x) == x && abs (x) < 1e10)
+      if (isnumeric (x) && x == fix (x) && abs (x) < 1e10)
         if (max (abs (real (x(:)))) == 0)
           dgt1 = 2;
         else
@@ -144,14 +144,14 @@
       if (ischar (arg))
         fmt = arg;
       else
-        if (isnumeric (x) && round (x) == x && abs (x) < (10 .^ arg))
+        if (isnumeric (x) && x == fix (x) && abs (x) < (10 .^ arg))
           fmt = sprintf ("%%%dd  ", arg);
         else
           fmt = sprintf ("%%%d.%dg", arg+7, arg);
         endif
       endif
     else
-      if (isnumeric (x) && round (x) == x && abs (x) < 1e10)
+      if (isnumeric (x) && x == fix (x) && abs (x) < 1e10)
         if (max (abs (x(:))) == 0)
           dgt = 2;
         else
--- a/scripts/general/rotdim.m	Wed Oct 05 12:00:31 2011 -0700
+++ b/scripts/general/rotdim.m	Wed Oct 05 13:10:10 2011 -0700
@@ -94,7 +94,7 @@
     endif
   else
     if (! (isvector (plane) && length (plane) == 2
-           && all (plane == round (plane)) && all (plane > 0)
+           && all (plane == fix (plane)) && all (plane > 0)
            && all (plane < (nd + 1)) && plane(1) != plane(2)))
       error ("rotdim: PLANE must be a 2 element integer vector defining a valid PLANE");
     endif
--- a/scripts/help/get_first_help_sentence.m	Wed Oct 05 12:00:31 2011 -0700
+++ b/scripts/help/get_first_help_sentence.m	Wed Oct 05 13:10:10 2011 -0700
@@ -50,7 +50,7 @@
     error ("get_first_help_sentence: NAME must be a string");
   endif
 
-  if (!isnumeric (max_len) || max_len <= 0 || max_len != round (max_len))
+  if (!isnumeric (max_len) || max_len <= 0 || max_len != fix (max_len))
     error ("get_first_help_sentence: MAX_LEN must be positive integer");
   endif
 
--- a/scripts/image/ind2rgb.m	Wed Oct 05 12:00:31 2011 -0700
+++ b/scripts/image/ind2rgb.m	Wed Oct 05 13:10:10 2011 -0700
@@ -40,7 +40,7 @@
   endif
 
   ## Check if X is an indexed image.
-  if (ndims (x) != 2 || any (x(:) != round (x(:))) || min (x(:)) < 1)
+  if (ndims (x) != 2 || any (x(:) != fix (x(:))) || min (x(:)) < 1)
     error ("ind2rgb: X must be an indexed image");
   endif
 
--- a/scripts/linear-algebra/commutation_matrix.m	Wed Oct 05 12:00:31 2011 -0700
+++ b/scripts/linear-algebra/commutation_matrix.m	Wed Oct 05 13:10:10 2011 -0700
@@ -76,12 +76,12 @@
   if (nargin < 1 || nargin > 2)
     print_usage ();
   else
-    if (! (isscalar (m) && m == round (m) && m > 0))
+    if (! (isscalar (m) && m == fix (m) && m > 0))
       error ("commutation_matrix: M must be a positive integer");
     endif
     if (nargin == 1)
       n = m;
-    elseif (! (isscalar (n) && n == round (n) && n > 0))
+    elseif (! (isscalar (n) && n == fix (n) && n > 0))
       error ("commutation_matrix: N must be a positive integer");
     endif
   endif
--- a/scripts/plot/figure.m	Wed Oct 05 12:00:31 2011 -0700
+++ b/scripts/plot/figure.m	Wed Oct 05 13:10:10 2011 -0700
@@ -41,7 +41,7 @@
       f = tmp;
       varargin(1) = [];
       nargs--;
-    elseif (isnumeric (tmp) && tmp > 0 && round (tmp) == tmp)
+    elseif (isnumeric (tmp) && tmp > 0 && tmp == fix (tmp))
       f = tmp;
       init_new_figure = true;
       varargin(1) = [];
@@ -88,4 +88,4 @@
 %!   assert (isfigure (hf));
 %! unwind_protect_cleanup
 %!   close (hf);
-%! end_unwind_protect
\ No newline at end of file
+%! end_unwind_protect
--- a/scripts/plot/legend.m	Wed Oct 05 12:00:31 2011 -0700
+++ b/scripts/plot/legend.m	Wed Oct 05 13:10:10 2011 -0700
@@ -158,7 +158,7 @@
 
   if (nargs > 0)
     pos = varargin{nargs};
-    if (isnumeric (pos) && isscalar (pos) && round (pos) == pos)
+    if (isnumeric (pos) && isscalar (pos) && pos == fix (pos))
       if (pos >= -1 && pos <= 4)
         position = [{"northeastoutside", "best", "northeast",
                      "northwest", "southwest", "southeast"}] {pos + 2};
--- a/scripts/polynomial/polyfit.m	Wed Oct 05 12:00:31 2011 -0700
+++ b/scripts/polynomial/polyfit.m	Wed Oct 05 13:10:10 2011 -0700
@@ -76,7 +76,7 @@
     error ("polyfit: X and Y must be vectors of the same size");
   endif
 
-  if (! (isscalar (n) && n >= 0 && ! isinf (n) && n == round (n)))
+  if (! (isscalar (n) && n >= 0 && ! isinf (n) && n == fix (n)))
     error ("polyfit: N must be a nonnegative integer");
   endif
 
--- a/scripts/signal/bartlett.m	Wed Oct 05 12:00:31 2011 -0700
+++ b/scripts/signal/bartlett.m	Wed Oct 05 13:10:10 2011 -0700
@@ -34,7 +34,7 @@
     print_usage ();
   endif
 
-  if (! (isscalar (m) && (m == round (m)) && (m > 0)))
+  if (! (isscalar (m) && (m == fix (m)) && (m > 0)))
     error ("bartlett: M has to be an integer > 0");
   endif
 
@@ -60,4 +60,4 @@
 %!error bartlett ();
 %!error bartlett (0.5);
 %!error bartlett (-1);
-%!error bartlett (ones(1,4));
\ No newline at end of file
+%!error bartlett (ones(1,4));
--- a/scripts/signal/blackman.m	Wed Oct 05 12:00:31 2011 -0700
+++ b/scripts/signal/blackman.m	Wed Oct 05 13:10:10 2011 -0700
@@ -33,7 +33,7 @@
     print_usage ();
   endif
 
-  if (! (isscalar (m) && (m == round (m)) && (m > 0)))
+  if (! (isscalar (m) && (m == fix (m)) && (m > 0)))
     error ("blackman: M has to be an integer > 0");
   endif
 
--- a/scripts/signal/detrend.m	Wed Oct 05 12:00:31 2011 -0700
+++ b/scripts/signal/detrend.m	Wed Oct 05 13:10:10 2011 -0700
@@ -45,7 +45,7 @@
       p = 0;
     elseif (ischar (p) && strcmpi (p, "linear"))
       p = 1;
-    elseif (!isscalar (p) || p < 0 || p != round (p))
+    elseif (!isscalar (p) || p < 0 || p != fix (p))
       error ("detrend: second input argument must be 'constant', 'linear' or a positive integer");
     endif
   else
--- a/scripts/signal/hamming.m	Wed Oct 05 12:00:31 2011 -0700
+++ b/scripts/signal/hamming.m	Wed Oct 05 13:10:10 2011 -0700
@@ -33,7 +33,7 @@
     print_usage ();
   endif
 
-  if (! (isscalar (m) && (m == round (m)) && (m > 0)))
+  if (! (isscalar (m) && (m == fix (m)) && (m > 0)))
     error ("hamming: M has to be an integer > 0");
   endif
 
--- a/scripts/signal/hanning.m	Wed Oct 05 12:00:31 2011 -0700
+++ b/scripts/signal/hanning.m	Wed Oct 05 13:10:10 2011 -0700
@@ -33,7 +33,7 @@
     print_usage ();
   endif
 
-  if (! (isscalar (m) && (m == round (m)) && (m > 0)))
+  if (! (isscalar (m) && (m == fix (m)) && (m > 0)))
     error ("hanning: M has to be an integer > 0");
   endif
 
--- a/scripts/specfun/factorial.m	Wed Oct 05 12:00:31 2011 -0700
+++ b/scripts/specfun/factorial.m	Wed Oct 05 13:10:10 2011 -0700
@@ -29,7 +29,7 @@
 function x = factorial (n)
   if (nargin != 1)
     print_usage ();
-  elseif (any (n(:) < 0 | n(:) != round (n(:))))
+  elseif (any (n(:) < 0 | n(:) != fix (n(:))))
     error ("factorial: N must all be nonnegative integers");
   endif
   x = round (gamma (n+1));
--- a/scripts/statistics/base/mode.m	Wed Oct 05 12:00:31 2011 -0700
+++ b/scripts/statistics/base/mode.m	Wed Oct 05 13:10:10 2011 -0700
@@ -49,7 +49,7 @@
     ## Find the first non-singleton dimension.
     (dim = find (sz > 1, 1)) || (dim = 1);
   else
-    if (!(isscalar (dim) && dim == round (dim))
+    if (!(isscalar (dim) && dim == fix (dim))
         || !(1 <= dim && dim <= nd))
       error ("mode: DIM must be an integer and a valid dimension");
     endif
--- a/scripts/statistics/base/skewness.m	Wed Oct 05 12:00:31 2011 -0700
+++ b/scripts/statistics/base/skewness.m	Wed Oct 05 13:10:10 2011 -0700
@@ -61,7 +61,7 @@
     ## Find the first non-singleton dimension.
     (dim = find (sz > 1, 1)) || (dim = 1);
   else
-    if (!(isscalar (dim) && dim == round (dim))
+    if (!(isscalar (dim) && dim == fix (dim))
         || !(1 <= dim && dim <= nd))
       error ("skewness: DIM must be an integer and a valid dimension");
     endif
--- a/scripts/statistics/base/statistics.m	Wed Oct 05 12:00:31 2011 -0700
+++ b/scripts/statistics/base/statistics.m	Wed Oct 05 13:10:10 2011 -0700
@@ -48,7 +48,7 @@
     ## Find the first non-singleton dimension.
     (dim = find (sz > 1, 1)) || (dim = 1);
   else
-    if (!(isscalar (dim) && dim == round (dim))
+    if (!(isscalar (dim) && dim == fix (dim))
         || !(1 <= dim && dim <= nd))
       error ("statistics: DIM must be an integer and a valid dimension");
     endif
--- a/scripts/statistics/tests/mcnemar_test.m	Wed Oct 05 12:00:31 2011 -0700
+++ b/scripts/statistics/tests/mcnemar_test.m	Wed Oct 05 13:10:10 2011 -0700
@@ -42,7 +42,7 @@
 
   if (! (min (size (x)) > 1) && issquare (x))
     error ("mcnemar_test: X must be a square matrix of size > 1");
-  elseif (! (all (all (x >= 0)) && all (all (x == round (x)))))
+  elseif (! (all (all (x >= 0)) && all (all (x == fix (x)))))
     error ("mcnemar_test: all entries of X must be nonnegative integers");
   endif