function c = rdivide(a,b)
%./ Fixed point MATLAB Coder library function for rdivide
%
%    See also MRDIVIDE.

%   Thomas A. Bryan and Becky Bryan, 30 December 2008
%   Copyright 2005-2021 The MathWorks, Inc.
%#codegen

coder.internal.implicitExpansionBuiltin;

coder.extrinsic('eml_fi_computeDivideType');
eml_allow_mx_inputs;

if coder.internal.isImplicitExpansionSupported()
    coder.internal.assert(coder.internal.isImplicitExpansionCompatible(a,b), ...
        'fixed:fi:DimsIncompatible');
else
    coder.internal.assert(coder.internal.scalexpCompatible(a, b), ...
                   'fixed:fi:DimAgree');
end

if eml_ambiguous_types
    % MATLAB Code Generation hasn't resolved the types yet, so return anything of
    % the right size
    if prod(size(a))>prod(size(b)) %#ok numel doesn't work for fi
        c = coder.ignoreConst(zeros(size(a))); 
    else
        c = coder.ignoreConst(zeros(size(b)));
    end
else
    eml_invariant((isnumeric(a)&&isnumeric(b)),...
                  'fixed:fi:operandMustBeNumeric');

    eml_invariant(isreal(b), ...
                  'fixed:fi:divideDenominatorNotReal');

    % The numerictype of the output must be determined from const inputs.
    % If we had called the fi::computeDivideType method directly with inputs A
    % and B, then we would have got the error "This expression must be
    % constant because its value determines the size or class of some
    % expression." 
    if isfi(a)
        Ta = numerictype(a);
    else
        Ta = class(a);
    end
    if isfi(b)
        Tb = numerictype(b);
    else
        Tb = class(b);
    end
    % rethrow the error with error id and error arguments
    [T, errid, errargs] = coder.const(@eml_fi_computeDivideType,Ta,Tb);
    eml_invariant(isempty(errid),errid,errargs{:});
    c = divide(T,a,b);
end

