标签:
float a=INFINITY;
if(a==INFINITY){
cout<<"a is inf"<<endl;
}else{
cout<<"a is not inf"<<endl;
}
输出结果为:a is inf
没问题。
但是:
float b=-INFINITY;
if(b==-INFINITY){
cout<<"b is -inf"<<endl;
}else{
cout<<"b is not -inf"<<endl;
}
输出结果为:b is not -inf
原因是-INFINITY对于float其实是溢出的。
所以永远不要用-INFINITY,如果已经大量使用,可批量将程序中所有-INFINITY替换成-0.5*INFINITY。
标签:
原文地址:http://www.cnblogs.com/wantnon/p/4464562.html