Show Lecture.Limits as a slide show.
<limits.h>
, alias <climits>
Symbol | Meaning |
---|---|
CHAR_BIT | char : number of bits |
SCHAR_MIN …SCHAR_MAX | signed char : range |
UCHAR_MAX | unsigned char : max value |
CHAR_MIN …CHAR_MAX | char : range |
SHRT_MIN …SHRT_MAX | short int : range |
USHRT_MAX | unsigned short int : max value |
INT_MIN …INT_MAX | int : range |
UINT_MAX | unsigned int : max value |
LONG_MIN …LONG_MAX | long int : range |
ULONG_MAX | unsigned long int : max value |
LLONG_MIN …LLONG_MAX | long long int : range |
ULLONG_MAX | unsigned long long int : max value |
<float.h>
, alias <cfloat>
Symbol | Meaning |
---|---|
FLT_DIG | float : mantissa decimal digits |
DBL_DIG | double : mantissa decimal digits |
LDBL_DIG | long double : mantissa decimal digits |
FLT_MIN_10_EXP …FLT_MAX_10_EXP | float : exponent range |
DBL_MIN_10_EXP …DBL_MAX_10_EXP | double exponent range |
LDBL_MIN_10_EXP …LDBL_MAX_10_EXP | long double : exponent range |
FLT_MIN …FLT_MAX | float : value range |
DBL_MIN …DBL_MAX | double : value range |
LDBL_MIN …LDBL_MAX | long double : value range |
Quick, now:
long double
?
short
?
size_t
?
<limits>
defines the template class numeric_limits
,
which is specialized for all built-in types.
static
methods and constants, including:
.min()
.max()
.digits10
.min_exponent10
.max_exponent10
.min()
& .max()
are methods,
not variables like .min_exponent10
.
constexpr
methods & constants. Fine.
cout << numeric_limits<int>::digits10 << '\n' << numeric_limits<int>::min() << '\n' << 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; // alias cout << nl::digits10 << '\n' << nl::min() << '\n' << nl::max() << '\n';
6 1.17549e-38 3.40282e+38
using nl = numeric_limits<double>; // alias cout << nl::digits10 << '\n' << nl::min() << '\n' << nl::max() << '\n';
15 2.22507e-308 1.79769e+308
numeric_limits<long double> nl; // instance cout << nl.digits10 << '\n' << nl.min() << '\n' << nl.max() << '\n';
18 3.3621e-4932 1.18973e+4932
Why do these both compile? One must be wrong!
cout << numeric_limits<size_t>::min << '\n' << numeric_limits<size_t>::min() << '\n';
1 0