function c = cond(A,p)
%MATLAB Code Generation Library Function

%   Copyright 1984-2016 The MathWorks, Inc.
%#codegen

coder.columnMajor;
eml_invariant(nargin >= 1, ...
    'MATLAB:minrhs');
eml_invariant(isa(A,'float'), ...
    'Coder:toolbox:unsupportedClass','cond',class(A));
eml_invariant(nargin == 1 || ((isscalar(p) && coder.internal.isBuiltInNumeric(p)) || coder.internal.isCharOrScalarString(p)), ...
    'Coder:toolbox:cond_3', ...
    'IfNotConst','Fail');
eml_invariant(ismatrix(A), ...
    'Coder:toolbox:cond_inputMustBe2D');
if nargin == 1
    p = 2;
end
if isempty(A)
    c = zeros(class(A));
elseif coder.internal.isBuiltInNumeric(p) && isequal(p,2)
   s = svd(A);
   if s(end) == 0
       % Handle singular matrix
       c = coder.internal.inf(class(A));
   else
       c = eml_rdivide(s(1),s(end));
   end
elseif size(A,1) ~= size(A,2)
   coder.internal.error('MATLAB:cond:normMismatchSizeA');
   % For embedded, execution continues, so go ahead and follow our own advice.
   c = cond(A,2);
else
   % We'll let NORM pick up any invalid p argument.
   c = norm(A,p) * norm(inv(A),p);
end
