function [aOut,bOut] = eml_fi_cast_two_inputs(a0,b0,operation,check4constNonFI,...
                                              check4numericData,check4sameDatatype)
% MATLAB Code Generation library function for casting the two inputs

% Copyright 2007-2014 The MathWorks, Inc.

%#codegen
coder.extrinsic('sprintf');
coder.extrinsic('eml_fi_math_with_same_types');

eml_allow_mx_inputs;

if ~isfi(b0) % (fi, non-fi)
    if check4constNonFI
        if (~eml_is_const(b0))
            if (length(operation) > 2)
                % Functional form: In {0}(fi,non-fi), the non-fi must be a constant.
                eml_invariant(false, ...
                    'fixed:coder:fiNonFiFcnForm_NonFiMustBeConstant', operation, operation);
            else
                % Operator form: In fi {0} non-fi, the non-fi must be a constant.
                eml_invariant(false, ...
                    'fixed:coder:fiNonFiOpForm_NonFiMustBeConstant', operation, operation);
            end
        end
    end        
    if check4numericData
        eml_invariant(isnumeric(b0), 'fixed:fi:operandMustBeNumeric');
    end        
    dType = eml_fi_getDType(a0);
elseif ~isfi(a0) % (non-fi, fi)
    if check4constNonFI
        if (~eml_is_const(a0))
            if (length(operation) > 2)
                % Functional form: In {0}(fi,non-fi), the non-fi must be a constant.
                eml_invariant(false, ...
                    'fixed:coder:fiNonFiFcnForm_NonFiMustBeConstant', operation, operation);
            else
                % Operator form: In fi {0} non-fi, the non-fi must be a constant.
                eml_invariant(false, ...
                    'fixed:coder:fiNonFiOpForm_NonFiMustBeConstant', operation, operation);
            end
        end
    end        
    if check4numericData
        eml_invariant(isnumeric(a0), 'fixed:fi:operandMustBeNumeric');
    end        
    dType = eml_fi_getDType(b0);
else % (fi, fi)
    ta = eml_typeof(a0); tb = eml_typeof(b0);
    if check4sameDatatype
        % Verify that the datatypes are the same
        % - Single with Double not allowed
        errID = coder.const(eml_fi_math_with_same_types(ta,tb));
        eml_invariant(isempty(errID), errID);
    end
    % The two datatypes are same
    dType = eml_fi_getDType(a0);
end

aOut = eml_cast(a0,dType);
bOut = eml_cast(b0,dType);

%--------------------------------------------------------------------------
