Mercurial > octave-nkf
comparison scripts/specfun/factorial.m @ 14062:5b49cafe0599 stable
Use non-negative, non-positive with hyphens in error messages.
* accumarray.m, polyfit.m, factorial.m, nchoosek.m, mcnemar_test.m, find.cc,
graphics.cc, sparse.cc: Use non-negative, non-positive with hyphens in error
messages for consistency with documentation.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Thu, 15 Dec 2011 22:03:03 -0800 |
parents | 984359717d71 |
children | 72c96de7a403 |
comparison
equal
deleted
inserted
replaced
14061:324b2ec6214d | 14062:5b49cafe0599 |
---|---|
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(:) != fix (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 non-negative integers"); |
34 endif | 34 endif |
35 x = round (gamma (n+1)); | 35 x = round (gamma (n+1)); |
36 endfunction | 36 endfunction |
37 | 37 |
38 %!assert (factorial(5), prod(1:5)) | 38 %!assert (factorial(5), prod(1:5)) |
39 %!assert (factorial([1,2;3,4]), [1,2;6,24]) | 39 %!assert (factorial([1,2;3,4]), [1,2;6,24]) |
40 %!assert (factorial(70), exp(sum(log(1:70))), -128*eps) | 40 %!assert (factorial(70), exp(sum(log(1:70))), -128*eps) |
41 %!fail ('factorial(5.5)', "must all be nonnegative integers") | 41 %!fail ('factorial(5.5)', "must all be non-negative integers") |
42 %!fail ('factorial(-3)', "must all be nonnegative integers") | 42 %!fail ('factorial(-3)', "must all be non-negative integers") |