C++中"Float"数据类型的范围值

pra*_*m k -3 c++

我需要验证浮点数据类型的最小值和最大值.

对于Ex:无符号__int8是0到255

像这样我需要扩展Float最小值和最大值.

float ----> 3.4E +/- 38(7位)如何扩展它.

Cha*_*had 5

您只想知道支持的范围?你可以用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只是.

  • 浮点类型的最小正值不是"最小"值吗?请参阅http://en.cppreference.com/w/cpp/types/numeric_limits/min以供参考. (2认同)