/*************************************************************************** miscm.cpp ------------------- W. Michael Brown Miscellaneous functions that do not deserve their own class __________________________________________________________________________ This file is part of the Math Library __________________________________________________________________________ begin : May 30 2003 copyright : (C) 2003 by W. Michael Brown email : wmbrown@sandia.gov ***************************************************************************/ #include "miscm.h" double am::square(double num) { return num*num; } // Rounds a number double am::round(double n) { double r=ceil(n); if (r-n>0.5) return floor(n); return r; } // Return the -1 for negative, 0 for zero, and 1 for positive int am::sign(double v) { if (v<0) return -1; if (v>0) return 1; return 0; } // Return the range of elements in a vector double am::range(const vector &v) { if (v.empty()) return 0; double min=v[0]; double max=v[0]; for (unsigned i=1; imax) max=v[i]; } return max-min; } // Return the average of elements in a vector double am::mean(const vector &v) { double sum=0; for (unsigned i=0; i(double,double); template float max(float,float); template unsigned max(unsigned,unsigned); template int max(int,int); } template numtyp am::max(numtyp one,numtyp two) { if (one>two) return one; return two; } // Return the min of two objects namespace am { template double min(double,double); template float min(float,float); template unsigned min(unsigned,unsigned); template int min(int,int); } template numtyp am::min(numtyp one,numtyp two) { if (one= big) { big =fabs(a[j][k]); irow=j; icol=k; } } else if (ipiv[k] > 1) { error.addwarning(303,9,"Invert", "Cannot invert a singular matrix."); return; } } ++(ipiv[icol]); if (irow !=icol) { for (l=0;l=1;l--) { if (indxr[l] != indxc[l]) for (k=0;k