function [detmat] = safedet(mat,thresh)

% if(nargin==1)
%     thresh=1e-20;
% end
% 
% ev = eig(mat);
% 
% index = find(ev<=thresh);
% 
% ev(index) = thresh * ones(length(index),1);
% 
% detmat = prod(ev);

detmat = det(mat)+1e-100;