function y = castLike(prototype, value) %#codegen
% castLike  Cast value to prototype's class and attributes.
%
%   castLike(PROTOTYPE, VALUE) casts VALUE to PROTOTYPE's class and
%   attributes.  castLike is a helper function for builtin CAST.
%
%   The type of the output will be identical to the type of
%   PROTOTYPE, regardless of data type override.
%
%   See also CAST.
        
%   Copyright 2012-2021 The MathWorks, Inc.
    coder.internal.allowHalfInputs;
    eml_invariant(isfi(prototype), 'fixed:fi:firstInputNotFi');
    eml_invariant(isnumeric(value) || islogical(value), 'fixed:coder:inputMustBeNumeric');
    if isreal(value) && ~isreal(prototype)
        y = complex(eml_fimathislocal(eml_cast(value,numerictype(prototype),fimath(prototype)),eml_fimathislocal(prototype)));
    else
        y = eml_fimathislocal(eml_cast(value,numerictype(prototype),fimath(prototype)),eml_fimathislocal(prototype));
    end
end

