% FACTORIAL FACTORIAL Return the factorial of n
%
% Usage
%
% Function File: factorial (n)
% Return the factorial of n. If n is scalar, this is
% equivalent to prod (1:n). If n is an array,
% the factorial of the elements of the array are returned.
function x = factorial (n)
if (nargin ~= 1)
error ('incorrect number of parameters');
elseif (any (n(:) < 0 | n(:) ~= round (n(:))))
error ('factorial: n must all be nonnegative integers');
end
x = round (gamma (n+1));
% Copyright (C) 2000, 2006, 2007 Paul Kienzle
%
% Ported to Freemat 3.6 by Ramon Figueroa-Centeno Jan 22, 2009
%
% This file is part of Octave.
%
% Octave is free software; you can redistribute it and/or modify it
% under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 3 of the License, or (at
% your option) any later version.
%
% Octave is distributed in the hope that it will be useful, but
% WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
% General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Octave; see the file COPYING. If not, see
% .