#include
using namespace std;
#include
const double eps=1e-8;//10^(-8)
//加上括号,防止宏定义可能带来的错误
#define Equ(a,b) ((fabs((a)-(b)))<(eps))//等于运算符==
#define More(a,b) (((a)-(b))>(eps))//大于运算符>
#define Less(a,b) (((a)-(b))<(-eps))//小于运算符<
#define MoreEqu(a,b) (((a)-(b))>(-eps))//大于等于>=
#define LessEqu(a,b) (((a)-(b))<(eps))//小于等于<=
int main()
{
double d1=3.14;
if(Equ(d1,3.14))
{
cout<<"true"<<endl;
}else
{
cout<<"false"<<endl;
}
if(More(3.14,3.12))
{
cout<<"true"<<endl;
}
if(Less(3.14,3.15))
{
cout<<"true"<<endl;
}
if(MoreEqu(3.14,3.14))
{
cout<<"true"<<endl;
}
if(LessEqu(3.14,3.14))
{
cout<<"true"<<endl;
}
return 0;
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)