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

来源:互联网 发布:雷尼绍测头编程 编辑:程序博客网 时间:2024/05/23 23:14

在各种纠结的算法中。偶尔出现怎么声明一个无穷大的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;}

运行结果如下:


 

原创粉丝点击