function ht = numerictype(varargin)
% MATLAB Code Generation Library function for numerictype the embedded.numerictype constructor.
%
%   All the possible function signatures are:
%
%       T = numerictype
%       T = numerictype(s)
%       T = numerictype(s, w)
%       T = numerictype(s, w, f)
%       T = numerictype(s, w, slope, bias)
%       T = numerictype(s, w, slopeadjustmentfactor, fixedexponent, bias)
%       T = numerictype(property1, value1, ...)
%       T = numerictype(T1, property1, value1, ...)
%       T = numerictype(A) will return the numerictype of A if A is a fi.
%

% $INCLUDE(DOC) toolbox/eml/lib/fixedpoint/numerictype.m $
% Copyright 2002-2014 The MathWorks, Inc.
%#codegen

coder.extrinsic('eml_numerictype_constructor_helper');
coder.extrinsic('num2str');
eml_transient;
coder.internal.prefer_const(varargin);

nvar = nargin;

maxWL = getFixedPointWidthLimit();

switch nvar
 case 0
  [ht,errid] = coder.const(@eml_numerictype_constructor_helper,maxWL);
  eml_invariant(isempty(errid),errid);
 
 % If input is a SL signal, 3 rounds on inference happens. The first round is for
 % size and the type is assumed to be double even if the signal is fixed-point
 % (unless specified in the model explorer). The code needs to compensate for this.
 case 1 % numerictype(s) or numerictype(fi)
   if eml_ambiguous_types
       [ht,errid,err_extra_arg] = coder.const(@eml_numerictype_constructor_helper,maxWL);
       if isempty(err_extra_arg)
           eml_invariant(isempty(errid),errid);
       else
           eml_invariant(isempty(errid),errid,err_extra_arg);
       end
   elseif isfi(varargin{1}) % If isfi(varargin{1}) return its numerictype
       ht = eml_typeof(varargin{1});
   else % if ~isfi(varargin{1}) and varargin{1} is a const
       eml_invariant(eml_is_const(varargin{1}),'fixed:numerictype:constructorSignArg');
       [ht,errid,err_extra_arg] = coder.const(@eml_numerictype_constructor_helper,maxWL,varargin{1});
       if isempty(err_extra_arg)
           eml_invariant(isempty(errid),errid);
       else
           eml_invariant(isempty(errid),errid,err_extra_arg);
       end
   end
   
  otherwise % numerictype(s,w) or numerictype('property',value, ...)
    for i = 1:length(varargin)

        eml_invariant(eml_is_const(varargin{i}),'fixed:numerictype:argMustBeConstant',i);
    end;
    [ht,errid,err_extra_arg] = coder.const(@eml_numerictype_constructor_helper,maxWL,varargin{:});
    if isempty(err_extra_arg)
        eml_invariant(isempty(errid),errid);
    else
        eml_invariant(isempty(errid),errid,err_extra_arg);
    end
end
