C++ 标准库中的numberic_limits

先来看一组example: 

#include      // std::cout
#include        // std::numeric_limits
int main () {
  std::cout << std::boolalpha;
  std::cout << "Minimum value for int: " << std::numeric_limits::min() << '\n';
  std::cout << "Maximum value for int: " << std::numeric_limits::max() << '\n';
  std::cout << "int is signed: " << std::numeric_limits::is_signed << '\n';
  std::cout << "Non-sign bits in int: " << std::numeric_limits::digits << '\n';
  std::cout << "int has infinity: " << std::numeric_limits::has_infinity << '\n';
  return 0;
}
Edit & Run


Possible output:

Minimum value for int: -2147483648
Maximum value for int: 2147483647
int is signed: true
Non-sign bits in int: 31
int has infinity: false

 

Minimum value for int: -2147483648
Maximum value for int: 2147483647
int is signed: true
Non-sign bits in int: 31
int has infinity: false

显然可以知道,该模板库涉及的是各个数值类型的极限值。

你可能感兴趣的:(C++ 标准库中的numberic_limits)