function r = eps(val_or_class)
% Embedded MATLAB Library function.
%
% Limitations:
% Can only handle 'single' or 'double'.

% $INCLUDE(DOC) toolbox/matlab/elmat/eps.m$
% Copyright 2002-2004 The MathWorks, Inc.
% $Revision: 1.1.6.6 $  $Date: 2004/08/10 01:33:59 $

if nargin == 1
  if ischar(val_or_class)
    switch val_or_class
     case 'double'
      val = 1;
     case 'single'
      val = single(1);
     otherwise
      eml_assert(0,'error',...
                 'Class must be ''single'' or ''double''');
    end
  else
    val = val_or_class;
  end
else
  val = 1;
end

eml_assert(isfloat(val),'Class must be ''single'' or ''double''');

%
% Except for denormals, if 2^E <= ABS(X) < 2^(E+1), then
%       EPS(X) = 2^(E-23) if ISA(X,'single')
%       EPS(X) = 2^(E-52) if ISA(X,'double')
% 

% This assignment initializes type and size of r. The value written to
% r is not used.
r = real(val);

for i = 1 : numel(r)
  v = val(i);
  switch class(v)
   case 'double',
    B = -52;
   case 'single',
    B = single(-23);
   otherwise,
    eml_assert(0,'Internal error: Unexpected class.');
  end
    
  if v == 1 || v == -1
    E = zeros(1,1,class(v));
  else
    E = floor(log(abs(v))/log(2));
  end
  
  r(i) = 2^(E+B);
end