%
% function lim=limits( x, show );
%
%          returns minimum and maximum values of x
%

function lim=limits( x, show )

	if ~isa(x,'double'), x = double(x); end;
	mi=min(x(:));
	ma=max(x(:));
	lim=[mi,ma];
	mi = lim(1); ma = lim(2);

	if (nargin>=2 && show) || (nargout==0),
		if accuracy( lim) > 0,
			acc = 0;
			if fix( mi)==0
				while fix( mi*10) == 0 && acc<9,
					mi = mi*10;
					acc = acc+1;
				end;
			elseif fix( ma)==0
				while fix( ma*10) == 0 && acc<9,
					ma = ma*10;
					acc = acc+1;
				end;
			end;
			s_acc = ['.',int2str(acc+3),'f'];
		else
			s_acc = 'd';
		end;
		if length( find( isnan( x(:))))>0
			fprintf(['Variable is inside [%',s_acc,',%',s_acc,'] -- Warning: NaN values exist!\n'],lim(1),lim(2));
		elseif issparse( x),
			fprintf(['Variable is inside [%',s_acc,',%',s_acc,'] -- Warning: Input is sparse!\n'],lim(1),lim(2));
		else
			fprintf(['Variable is inside [%',s_acc,',%',s_acc,']\n'],lim(1),lim(2));
		end;
	end;

return;