function y = mpower(x1, x2)
% Embedded MATLAB Library function.
%
% Limitations:
% Fractional powers of matrices are not supported. 
%
% $INCLUDE(DOC) toolbox/eml/lib/matlab/mpower.m $
% Copyright 2002-2004 The MathWorks, Inc.
% $Revision: 1.1.6.4 $  $Date: 2004/12/16 21:55:23 $

eml_assert(nargin > 1, 'error', 'Not enough input arguments.');
eml_assert(isfloat(x1), 'error', ['Function ''mpower'' is not defined for values of class ''' class(x1) '''.']);
eml_assert(isfloat(x2), 'error', ['Function ''mpower'' is not defined for values of class ''' class(x2) '''.']);
eml_assert((isscalar(x1) && isscalar(x2)) || (size(x1,1)==size(x1,2) && isscalar(x2) && isreal(x2)), ...
    'Matrix exponentiation of these input types is not supported.');
eml_assert(length(size(x1))<=2, 'Input arguments must be 2-D.');

if isscalar(x1)
    y = x1 .^ x2;
elseif floor(x2) == x2
    e = uint32(abs(x2));
    s = x1;
    if isreal(x1)
        y = eye(size(x1),class(x1));
    else
        y = complex(eye(size(x1),class(x1)));
    end
    while (e > 0)
        if eml_bitand(e,uint32(1))
            y = y * s;
        end
        s = s * s;
        e = eml_rshift(e,uint32(1));
    end
    if (x2 < 0)
        y = inv(y);
    end
else
    %This case is a placeholder for fractional powers.
    error('Fractional powers of matrices are not supported.');
    y = eye(size(x1),class(x1));
end

