comparison scripts/specfun/factorial.m @ 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 fd0a3ac60b0e
children 5b49cafe0599
comparison
equal deleted inserted replaced
13278:04edb15d7966 13279:984359717d71
27 ## @end deftypefn 27 ## @end deftypefn
28 28
29 function x = factorial (n) 29 function x = factorial (n)
30 if (nargin != 1) 30 if (nargin != 1)
31 print_usage (); 31 print_usage ();
32 elseif (any (n(:) < 0 | n(:) != round (n(:)))) 32 elseif (any (n(:) < 0 | n(:) != fix (n(:))))
33 error ("factorial: N must all be nonnegative integers"); 33 error ("factorial: N must all be nonnegative integers");
34 endif 34 endif
35 x = round (gamma (n+1)); 35 x = round (gamma (n+1));
36 endfunction 36 endfunction
37 37