c++的float类型包含的最值问题....

在各种纠结的算法中。偶尔出现怎么声明一个无穷大的float宏.....

 方法一:

   头文件:#include或#include

   宏: FLT_MAX

   最大值:3.402823466e+38F


方法二:

   头文件:#include

   定义方式:float floatMax = numeric_limits::max();

   如下例:(借用网友的.....)

#include 
#include 

using namespace std;

int main()
{
 int intMax = numeric_limits::max();
 int intMin = numeric_limits::min();

 float floatMax = numeric_limits::max();
 float floatMin = numeric_limits::min();

 cout << intMax << " " << intMin << endl;
 cout << floatMax << " " << floatMin << endl;

  return 0;
}

运行结果如下:


 

你可能感兴趣的:(c++)