<limits.h> , alias <climits> | |
---|---|
Symbol | Meaning |
CHAR_BIT | Number of bits in a char |
SCHAR_MIN …SCHAR_MAX | Range of signed char |
UCHAR_MAX | Max value of unsigned char |
CHAR_MIN …CHAR_MAX | Range of char |
SHRT_MIN …SHRT_MAX | Range of short int |
USHRT_MAX | Max value of unsigned short int |
INT_MIN …INT_MAX | Range of int |
UINT_MAX | Max value of unsigned int |
LONG_MIN …LONG_MAX | Range of long int |
ULONG_MAX | Max value of unsigned long int |
LLONG_MIN …LLONG_MAX | Range of long long int |
ULLONG_MAX | Max value of unsigned long long int |
<float.h> , alias <cfloat> | |
---|---|
Symbol | Meaning |
FLT_DIG | Mantissa decimal digits (float ) |
DBL_DIG | Mantissa decimal digits (double ) |
LDBL_DIG | Mantissa decimal digits (long double ) |
FLT_MIN_10_EXP …FLT_MAX_10_EXP | Exponent range (float ) |
DBL_MIN_10_EXP …DBL_MAX_10_EXP | Exponent range (double ) |
LDBL_MIN_10_EXP …LDBL_MAX_10_EXP | Exponent range (long double ) |
FLT_MIN …FLT_MAX | Value range (float ) |
DBL_MIN …DBL_MAX | Value range (double ) |
LDBL_MIN …LDBL_MAX | Value range (long double ) |
Quick, now:
long double
?
short
?
size_t
?
<limits>
defines the template class numeric_limits
,
which is specialized for all built-in types.
It has many static
methods and constants, including:
.min()
.max()
.digits10
.min_exponent10
.max_exponent10
It is not clear why .min()
and .max()
are not constants.
Surely, these values are known at compile-time. In fact, for C++11,
they’re all constexpr
. Fine.
cout << numeric_limits<int>::digits10 << ' ' << numeric_limits<int>::min() << ' ' << numeric_limits<int>::max() << '\n';
9 -2147483648 2147483647
::
. We’d use .
if we had an instance of this class.
digits10
is a constant, not a method.
typedef numeric_limits<float> nl; cout << nl::digits10 << ' ' << nl::min() << ' ' << nl::max() << '\n';
6 1.17549e-38 3.40282e+38
using nl = numeric_limits<double>; cout << nl::digits10 << ' ' << nl::min() << ' ' << nl::max() << '\n';
15 2.22507e-308 1.79769e+308
auto nl = numeric_limits<long double>(); // an instance cout << nl.digits10 << ' ' << nl.min() << ' ' << nl.max() << '\n';
18 3.3621e-4932 1.18973e+4932
Why do these both compile? One must be wrong!
cout << numeric_limits<unsigned short>::min << '\n'; cout << numeric_limits<unsigned short>::min() << '\n';
1 0