function yfi = uminus(xfi)
% MATLAB Code Generation Library function for @fi/uminus.
%
% UMINUS(A) will return the unary minus of A

% $INCLUDE(DOC) toolbox/eml/lib/fixedpoint/@embedded/@fi/uminus.m $
% Copyright 2002-2016 The MathWorks, Inc.
%#codegen

if eml_ambiguous_types
    yfi = coder.ignoreConst(zeros(size(xfi)));
    return;
end

% Get the numerictype and fimath of xfi
tx = eml_typeof(xfi);
fx = eml_fimath(xfi);

if isscaledtype(xfi)
  % FI objects with Fixed datatype
  ty = numerictype(tx,'Bias',-tx.Bias);
  doSaturate = coder.const(isequal(fx.OverflowMode,'saturate'));
  if ~isslopebiasscaled(tx) && ~(tx.Signed) && doSaturate && isfixed(xfi)
    z = fi(zeros(size(xfi)),0,tx.WordLength,0,'DataTypeOverride','Off');
    yfireim = eml_dress(z,ty,fx);
    if isreal(xfi)
      yfi = eml_fimathislocal(yfireim,eml_fimathislocal(xfi));
      return;
    else
      yfi = eml_fimathislocal(complex(yfireim,yfireim),eml_fimathislocal(xfi));
      return;
    end
  end
elseif isfloat(xfi)
  % True Double or True Single FI
  ty = tx;
else
  % FI datatype not supported
  eml_fi_assert_dataTypeNotSupported('UMINUS');
end

% call eml_uminus
yfi = eml_uminus(xfi,ty,fx);
yfi = eml_fimathislocal(yfi,eml_fimathislocal(xfi));
