function z = realpow(x,y)
%MATLAB Code Generation Library Function

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

eml_invariant(nargin >= 2,'MATLAB:minrhs');
eml_invariant(isfloat(x),'Coder:toolbox:unsupportedClass',mfilename,class(x));
eml_invariant(isfloat(y),'Coder:toolbox:unsupportedClass',mfilename,class(y));
eml_invariant(isreal(x) && isreal(y),'Coder:toolbox:realpow_4');
eml_invariant(noerrors(x,y),'MATLAB:realpow:complexResult');
z = coder.internal.applyBinaryScalarFunction(mfilename, ...
    coder.internal.scalarEg(x,y),@coder.internal.scalar.realpow,x,y);

%--------------------------------------------------------------------------

function p = noerrors(x,y)
p = true;
if isscalar(y)
    if y(1) ~= coder.internal.scalar.floor(y(1))
        p = coder.internal.vAllOrAny('all',x,@notLT0);
    end
elseif isscalar(x)
    if x(1) < 0
        p = coder.internal.vAllOrAny('all',y,@integerValue);
    end
else
    for k = 1:numel(x)
        p = p && (notLT0(x(k)) || integerValue(y(k)));
    end
end

%--------------------------------------------------------------------------

function p = notLT0(x)
p = ~(x < 0);

function p = integerValue(y)
p = ~(y ~= coder.internal.scalar.floor(y));

%--------------------------------------------------------------------------
