function n = factorial(n)
% Embedded MATLAB Library function.
%
% Limitations:
% No known limitations.
%
% $INCLUDE(DOC) toolbox/eml/lib/matlab/factorial.m $
% Copyright 2002-2004 The MathWorks, Inc.

eml_assert(isfloat(n) && isreal(n), ...
    'N must be a matrix of non-negative floating-point integers.');

dim = numel(n);
for k = 1:dim
    N = n(k);
    if floor(N) ~= N || N < 0
        error('N must be a matrix of non-negative integers.');
    end
    f = cast(1,class(n));
    for m = 2:N
        f = f*cast(m,class(n));
        if isinf(f), break; end
    end
    n(k) = f;
end
