function tf = isreal(x)
%ISREAL True for real distributed array
%   TF = ISREAL(X)
%   
%   Example:
%       N = 1000;
%       rp = 3 * distributed.ones(N);
%       ip = 4 * distributed.ones(N);
%       D = complex(rp, ip);
%       f = isreal(D)
%   
%   returns f = false.
%   
%   See also ISREAL, DISTRIBUTED, DISTRIBUTED/COMPLEX, DISTRIBUTED/ONES.


%   Copyright 2006-2022 The MathWorks, Inc.

% Protect against broken distributed.
errorIfInvalid(x);

% Check if we already know the answer (saves contacting workers)
if x.IsReal.isKnown()
    tf = x.IsReal.get();
    return;
end

if islogical(x) || ischar(x)
    % Logical and char are always real
    tf = true;

elseif isnumeric(x)
    % Numeric could be real or complex so we have to actually check
    tf = distributedutil.distributedSpmdWrapper(@isreal, x);

else
    % Other types are always false
    tf = false;
end

% Store for future use
x.IsReal.set(tf);
