function S = sign(X)
% MATLAB Code Generation Library function.
%
% Limitations:
% 1) Complex numbers do not work.
% 2) NaN friendly but not correct.

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

eml_invariant(nargin==1,'MATLAB:narginchk:notEnoughInputs');
eml_invariant(isreal(X),'fixed:fi:notDefinedForComplexFi','sign');

S = zeros(size(X),'int8');

for m = 1:numel(X)
  if isnan(X(m))
    S(m) = 1;
  elseif X(m) > 0
    S(m) = 1;
  elseif X(m) < 0
    S(m) = -1;
  end
end

