?? comm.inl
字號:
// Comm.inl 公共函數(shù)(方法)定義
// Ver 1.0.0.0
// 版權(quán)所有(C) 何渝, 2002
// 最后修改: 2002.5.31
#ifndef _COMM_INL
#define _COMM_INL
template <class T>
inline long double //判斷絕對值
Abs(const T& x)
{
complex<long double> cld(x);
long double ldAbs = abs(cld);
return(ldAbs);
}
template <class T>
inline T //取x符號,+-0
Sgn(const T& x)
{
return x < T(0) ? T(-1) : (x > T(0) ? T(1) : T(0));
}
inline bool //判斷float浮點數(shù)相等
FloatEqual(float lhs, float rhs)
{
if (Abs(lhs - rhs) < FLOATERROR)
return true;
else
return false;
}
inline bool //判斷float浮點數(shù)不相等
FloatNotEqual(float lhs, float rhs)
{
if (Abs(lhs - rhs) >= FLOATERROR)
return true;
else
return false;
}
inline bool //判斷double浮點數(shù)相等
FloatEqual(double lhs, double rhs)
{
if (Abs(lhs - rhs) < DOUBLEERROR)
return true;
else
return false;
}
inline bool //判斷double浮點數(shù)不相等
FloatNotEqual(double lhs, double rhs)
{
if (Abs(lhs - rhs) >= DOUBLEERROR)
return true;
else
return false;
}
inline bool //比較兩long double浮點數(shù)相等
FloatEqual(long double lhs, long double rhs)
{
if (Abs(lhs - rhs) < LONGDOUBLEERROR)
return true;
else
return false;
}
inline bool //比較兩long double浮點數(shù)不相等
FloatNotEqual(long double lhs, long double rhs)
{
if (Abs(lhs - rhs) >= LONGDOUBLEERROR)
return true;
else
return false;
}
template <class T>
inline T
Min(const T& x, const T& y) //比較x與y,返回小者
{
if(x < y)
return x;
else
return y;
}
template <class T>
T Max(const T& x, const T& y) //求x與y的最大值,返回大者
{
if(x > y)
return x;
else
return y;
}
//打印數(shù)組(向量)所有元素值
template <class T>
void ValarrayPrint(const valarray<T>& vOut)
{
size_t vsize = vOut.size(); //取數(shù)組元素的個數(shù)
for(size_t st=0; st<vsize; st++)
{
cout.width(15); //元素對齊,讓每個元素占15列
cout << vOut[st] << ' ';
}
cout << endl;
}
//打印某個指定數(shù)組(向量)元素值
template <class T>
void ValarrayPrint(const valarray<T>& vOut, size_t sPosition)
{
cout.width(15); //元素對齊,讓每個元素占15列
cout << vOut[sPosition] << endl;
}
#endif // _COMM_INL
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -