在各种纠结的算法中。偶尔出现怎么声明一个无穷大的float宏.....
方法一:
头文件:#include<floati.h>或#include<cfloat>
宏: FLT_MAX
最大值:3.402823466e+38F
方法二:
头文件:#include <limits>
定义方式:float floatMax = numeric_limits<float>::max();
如下例:(借用网友的.....)
- #include <iostream>
- #include <limits>
- using namespace std;
- int main()
- {
- int intMax = numeric_limits<int>::max();
- int intMin = numeric_limits<int>::min();
- float floatMax = numeric_limits<float>::max();
- float floatMin = numeric_limits<float>::min();
- cout << intMax << " " << intMin << endl;
- cout << floatMax << " " << floatMin << endl;
- return 0;
- }
运行结果如下: