# HG changeset patch # User Rik # Date 1317845410 25200 # Node ID 984359717d71a2259aac8d3f69c70d2d12da66bd # Parent 04edb15d7966f4185caf14e2d5acf8610ae3fa98 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. diff -r 04edb15d7966 -r 984359717d71 scripts/general/num2str.m --- 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 diff -r 04edb15d7966 -r 984359717d71 scripts/general/rotdim.m --- 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 diff -r 04edb15d7966 -r 984359717d71 scripts/help/get_first_help_sentence.m --- 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 diff -r 04edb15d7966 -r 984359717d71 scripts/image/ind2rgb.m --- 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 diff -r 04edb15d7966 -r 984359717d71 scripts/linear-algebra/commutation_matrix.m --- 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 diff -r 04edb15d7966 -r 984359717d71 scripts/plot/figure.m --- 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 diff -r 04edb15d7966 -r 984359717d71 scripts/plot/legend.m --- 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}; diff -r 04edb15d7966 -r 984359717d71 scripts/polynomial/polyfit.m --- 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 diff -r 04edb15d7966 -r 984359717d71 scripts/signal/bartlett.m --- 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)); diff -r 04edb15d7966 -r 984359717d71 scripts/signal/blackman.m --- 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 diff -r 04edb15d7966 -r 984359717d71 scripts/signal/detrend.m --- 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 diff -r 04edb15d7966 -r 984359717d71 scripts/signal/hamming.m --- 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 diff -r 04edb15d7966 -r 984359717d71 scripts/signal/hanning.m --- 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 diff -r 04edb15d7966 -r 984359717d71 scripts/specfun/factorial.m --- 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)); diff -r 04edb15d7966 -r 984359717d71 scripts/statistics/base/mode.m --- 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 diff -r 04edb15d7966 -r 984359717d71 scripts/statistics/base/skewness.m --- 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 diff -r 04edb15d7966 -r 984359717d71 scripts/statistics/base/statistics.m --- 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 diff -r 04edb15d7966 -r 984359717d71 scripts/statistics/tests/mcnemar_test.m --- 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