function [f,e] = log2(x)
%MATLAB Code Generation Library Function

%   Copyright 2006-2014 The MathWorks, Inc.
%#codegen

coder.replace;
coder.internal.allowHalfInputs;
eml_invariant(nargin > 0,'MATLAB:minrhs');
eml_invariant(isfloat(x),'Coder:toolbox:unsupportedClass',mfilename,class(x));
if nargout == 2
    if ~isreal(x)
        if ~coder.setwarningflag
            coder.internal.warning('MATLAB:log2:ignoredImagPart');
        end
    end
    [f,e] = coder.internal.applyScalarFunction('log2_nargout_eq_2', ...
        zeros('like',real(x)),@coder.internal.scalar.log2,x);
else
    if eml_is_const(isscalar(x)) && isscalar(x)
        coder.internal.prefer_const(x);
    end
    if isreal(x)
        if coder.internal.isDomainError(x,@lt,zeros('like',x))
            coder.internal.error('Coder:toolbox:ElFunDomainError',mfilename);
        end
    end
    f = coder.internal.applyScalarFunction('log2_nargout_eq_1', ...
        zeros('like',x),@coder.internal.scalar.log2,x);
end
