function [x, y] = cordicpol2cart(theta, r, varargin)
% CORDICPOL2CART CORDIC-based approximation of polar-to-Cartesian.

% Copyright 2009-2014 The MathWorks, Inc.
%#codegen

coder.allowpcode('plain');

if eml_ambiguous_types
    if numel(double(theta)) > 1
        sz = size(theta);
    else
        sz = size(r);
    end
    x = coder.ignoreConst(zeros(sz));
    y = coder.ignoreConst(zeros(sz));
else
    coder.internal.prefer_const(theta);
    coder.internal.prefer_const(r);
    if nargin > 2
        coder.internal.prefer_const(varargin);
    end
    
    eml_invariant(isreal(r), ...
        'fixed:cordic:pol2cart_invalidR');
    
    % Use shared CORDICROTATE function for CORDICPOL2CART computation
    % ---------------------------------------------------------------
    if nargin > 2
        v = cordicrotate(theta, r, varargin{1:end});
    else
        v = cordicrotate(theta, r);
    end
    x = real(v);
    y = imag(v);
end

end

