我需要验证浮点数据类型的最小值和最大值.
对于Ex:无符号__int8是0到255
像这样我需要扩展Float最小值和最大值.
float ----> 3.4E +/- 38(7位)如何扩展它.
您只想知道支持的范围?你可以用numeric_limits它.
#include <iostream>
#include <limits>
using namespace std;
int main()
{
// your code goes here
std::cout << "Float Range"
<< std::numeric_limits<float>::min() << " / "
<< std::numeric_limits<float>::max() << '\n';
return 0;
}
Run Code Online (Sandbox Code Playgroud)
正如评论中所讨论的,std::numeric_limits<float>::min()给出a的最小正值float,同时std::numeric_limits<float>::lowest()给出最大可能的负值,并且可能更合适. lowest()但C++11只是.