1,代码先行
示例:
#include<iostream>
#include<limits>
using namespace std;
int main()
{
float inf_pos = numeric_limits<float>::infinity();
float inf_neg = -1*inf_pos;
cout << "inf_pos = " << inf_pos << endl;
cout << "inf_neg = " << inf_neg << endl;
cout << "inf_pos + inf_neg = " << inf_pos + inf_neg << endl;
cout << "1.0/0.0 = "<< 1.0/0.0 << endl;
cout << "-1.0/0.0 = "<< -1.0/0.0 << endl;
cout << "1/0 = "<< 1/0 << endl;
cout << "-1/0 = "<< -1/0 << endl;
return 0;
}
注意头文件 limits
2,运行
1.0/0.0 包含进了IEEE754,而1/0并没有,所以报错了