function y = round(a)
%ROUND  Fixed-point MATLAB Code Generation function for rounding towards nearest integer 
%
%   ROUND(A) returns the result of rounding A towards nearest integer -
%   ties round away from zero.

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

coder.extrinsic('eml_get_out_numerictype_for_round');
eml_allow_mx_inputs; 

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

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

if isfloat(a)
    [Ty,Fy,DType] = eml_fi_type_math_and_dtype(a);
    aDType = eml_cast(a,DType);
    yDType = round(aDType);
    y = eml_fimathislocal(eml_cast(yDType,Ty,Fy),eml_fimathislocal(a));
    
elseif isscaleddouble(a)
    t_a = numerictype(a);
    f_a = eml_fimath(a);
    eml_invariant(~isslopebiasscaled(t_a), ...
        'fixed:coder:slopeBiasInputsNotSupported');
    t_y = coder.const(eml_get_out_numerictype_for_round(t_a,1));
    y1 = fi(round(double(a)),t_y,f_a);
    y = eml_fimathislocal(y1,eml_fimathislocal(a));     
    
else
    y = eml_fi_round_helper(a);
end
