function c = le(a0,b0)
% MATLAB Code Generation function the @fi/le (<=) operation

% $INCLUDE(DOC) toolbox/eml/lib/fixedpoint/@embedded/@fi/le.m $
% Copyright 2002-2021 The MathWorks, Inc.
%#codegen

coder.internal.implicitExpansionBuiltin;

eml_allow_mx_inputs;

eml_invariant(nargin > 1, 'fixed:coder:notEnoughInputArguments');
if coder.internal.isImplicitExpansionSupported
    coder.internal.assert(coder.internal.isImplicitExpansionCompatible(a0,b0), 'fixed:fi:DimsIncompatible');
else
    coder.internal.assert(coder.internal.scalexpCompatible(a0,b0), 'fixed:fi:DimAgree');
end

if eml_ambiguous_types
    c = eml_le(a0,b0);
    return;
end

if isfi(a0)
    F = eml_fimath(a0);
else
    F = eml_fimath(b0);
end
fixedOpFloatYieldsFloating = coder.const(strcmpi(get(F,'FixedOpFloatingYields'),'Floating'));

if ( (isfi(a0) && isscaledtype(a0)) || ...
     (isfi(b0) && isscaledtype(b0)) )
    % One of the inputs (or both) is FI objects with Fixed datatype

    if isfi(a0) && ~isfi(b0) && isinteger(b0)
        % Cast the integer to fi and recurse once
        c = le(a0, fi(b0));
        return

    elseif ~isfi(a0) && isinteger(a0) && isfi(b0)
        % Cast the integer to fi and recurse once
        c = le(fi(a0), b0);
        return

    elseif isfi(a0) && ~isfi(b0) && islogical(b0)
        % Cast the logical to fi and recurse once
        c = le(a0, fi(b0,0,1,0));
        return

    elseif ~isfi(a0) && islogical(a0) && isfi(b0)
        % Cast the logical to fi and recurse once
        c = le(fi(a0,0,1,0), b0);
        return

    elseif isfi(a0) && ~isfi(b0) % fi relop non-fi

        if isa(b0,'double') && fixedOpFloatYieldsFloating
            c = double(a0) <= b0;
            return
        elseif isa(b0,'single') && fixedOpFloatYieldsFloating
            c = single(a0) <= b0;
            return
        end

        coder.internal.prefer_const(b0);
        eml_invariant(eml_is_const(b0), 'fixed:coder:fiNonFiOpForm_NonFiMustBeConstant', '<=', '<=');
        a = a0;
        b = eml_type_relop_const(a0, b0, 'le');
        
    elseif ~isfi(a0) && isfi(b0) % non-fi relop fi

        if isa(a0,'double') && fixedOpFloatYieldsFloating
            c = a0 <= double(b0);
            return
        elseif isa(a0,'single') && fixedOpFloatYieldsFloating
            c = a0 <= single(b0);
            return
        end

        coder.internal.prefer_const(a0);
        eml_invariant(eml_is_const(a0), 'fixed:coder:fiNonFiOpForm_NonFiMustBeConstant', '<=', '<=');
        a = eml_type_relop_const(b0, a0, 'ge');
        b = b0;
        
    else % fi relop fi OR nonfi relop nonfi
        
        a = a0; 
        b = b0;
        
    end

    [a1,b1] = eml_make_same_complexity(a,b);
    c = eml_le(a1,b1);

elseif ( isfi(a0) && isfloat(a0) ) || ...
        ( isfi(b0) && isfloat(b0) )
    % True Double or True Single FI
    
    % call MATLAB LE directly
    check4constNonFI   = false; % non-FI need not be constant
    check4numericData  = ~islogical(a0) && ~islogical(b0);  % non-FI must be numeric or logical
    check4sameDatatype = false; % The datatypes of two inputs need not be same
    [a,b] = eml_fi_cast_two_inputs(a0,b0,'<=',check4constNonFI,...
                                   check4numericData,check4sameDatatype);

    c = eml_le(a,b);

else
    % FI datatype not supported
    eml_fi_assert_dataTypeNotSupported('LE');
end
