function y = nearest(x)
%MATLAB Code Generation Library Function

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

eml_allow_mx_inputs; 

if eml_ambiguous_types
    y = coder.ignoreConst(zeros(size(x)));
    return;
end

eml_invariant(nargin == 1, ...
    'fixed:coder:incorrectNumberOfInputs');

eml_invariant(isa(x,'numeric'), ...
    'fixed:coder:functionNotDefinedFor1stArgType', ...
    'NEAREST', class(x));
            
if isempty(x) || isinteger(x)
    y = x;
elseif isreal(x)
    y = floor(x+.5);
else
    y = floor(x+(.5+.5i));
end
