Contents |
Limits of core language integer types | |
Defined in header <limits.h> | |
BOOL_WIDTH (C23) | bit width of_Bool (macro constant) |
CHAR_BIT | bit width of byte (macro constant)[edit] |
MB_LEN_MAX | maximum number of bytes in a multibyte character (macro constant)[edit] |
CHAR_WIDTH (C23) | bit width ofchar, same asCHAR_BIT(macro constant) |
CHAR_MIN | minimum value ofchar (macro constant)[edit] |
CHAR_MAX | maximum value ofchar (macro constant)[edit] |
SCHAR_WIDTHSHRT_WIDTHINT_WIDTHLONG_WIDTHLLONG_WIDTH (C23)(C23)(C23)(C23)(C23) | bit width ofsignedchar,short,int,long, andlonglong respectively (macro constant) |
SCHAR_MINSHRT_MININT_MINLONG_MINLLONG_MIN (C99) | minimum value ofsignedchar,short,int,long andlonglong respectively (macro constant)[edit] |
SCHAR_MAXSHRT_MAXINT_MAXLONG_MAXLLONG_MAX (C99) | maximum value ofsignedchar,short,int,long andlonglong respectively (macro constant)[edit] |
UCHAR_WIDTHUSHRT_WIDTHUINT_WIDTHULONG_WIDTHULLONG_WIDTH (C23)(C23)(C23)(C23)(C23) | bit width ofunsignedchar,unsignedshort,unsignedint,unsignedlong, andunsignedlonglong respectively (macro constant) |
UCHAR_MAXUSHRT_MAXUINT_MAXULONG_MAXULLONG_MAX (C99) | maximum value ofunsignedchar,unsignedshort,unsignedint, unsignedlong andunsignedlonglong respectively (macro constant)[edit] |
BITINT_MAXWIDTH (C23) | maximum widthN supported by the declaration of a bit-precise integer in the type specifier_BitInt(N), greater than or equal toULLONG_WIDTH(macro constant) |
Limits of library type aliases | |
Defined in header <stdint.h> | |
PTRDIFF_WIDTH (C23) | bit width of object ofptrdiff_t type (macro constant) |
PTRDIFF_MIN (C99) | minimum value ofptrdiff_t (macro constant)[edit] |
PTRDIFF_MAX (C99) | maximum value ofptrdiff_t (macro constant)[edit] |
SIZE_WIDTH (C23) | bit width of object ofsize_t type (macro constant) |
SIZE_MAX (C99) | maximum value ofsize_t (macro constant)[edit] |
SIG_ATOMIC_WIDTH (C23) | bit width of object ofsig_atomic_t type (macro constant) |
SIG_ATOMIC_MIN (C99) | minimum value ofsig_atomic_t (macro constant)[edit] |
SIG_ATOMIC_MAX (C99) | maximum value ofsig_atomic_t (macro constant)[edit] |
WINT_WIDTH (C23) | bit width of object ofwint_t type (macro constant) |
WINT_MIN (C99) | minimum value ofwint_t(macro constant)[edit] |
WINT_MAX (C99) | maximum value ofwint_t(macro constant)[edit] |
Defined in header <wchar.h> | |
Defined in header <stdint.h> | |
WCHAR_WIDTH (C23) | bit width of object ofwchar_t type (macro constant) |
WCHAR_MIN (C99) | minimum value ofwchar_t (macro constant)[edit] |
WCHAR_MAX (C99) | maximum value ofwchar_t (macro constant)[edit] |
The types of these constants, other thanCHAR_BIT andMB_LEN_MAX, are required to match the results of theintegral promotions as applied to objects of the types they describe:CHAR_MAX may have typeint orunsignedint, but neverchar. SimilarlyUSHRT_MAX may not be of an unsigned type: its type may beint.
A freestanding implementation may lacksig_atomic_t and/orwint_t typedef names, in which case theSIG_ATOMIC_* and/orWINT_* macros are correspondingly absent.
#include <limits.h>#include <stdint.h>#include <stdio.h> int main(void){printf("CHAR_BIT = %d\n", CHAR_BIT);printf("MB_LEN_MAX = %d\n\n", MB_LEN_MAX); printf("CHAR_MIN = %+d\n", CHAR_MIN);printf("CHAR_MAX = %+d\n", CHAR_MAX);printf("SCHAR_MIN = %+d\n", SCHAR_MIN);printf("SCHAR_MAX = %+d\n", SCHAR_MAX);printf("UCHAR_MAX = %u\n\n", UCHAR_MAX); printf("SHRT_MIN = %+d\n", SHRT_MIN);printf("SHRT_MAX = %+d\n", SHRT_MAX);printf("USHRT_MAX = %u\n\n", USHRT_MAX); printf("INT_MIN = %+d\n", INT_MIN);printf("INT_MAX = %+d\n", INT_MAX);printf("UINT_MAX = %u\n\n", UINT_MAX); printf("LONG_MIN = %+ld\n", LONG_MIN);printf("LONG_MAX = %+ld\n", LONG_MAX);printf("ULONG_MAX = %lu\n\n", ULONG_MAX); printf("LLONG_MIN = %+lld\n", LLONG_MIN);printf("LLONG_MAX = %+lld\n", LLONG_MAX);printf("ULLONG_MAX = %llu\n\n", ULLONG_MAX); printf("PTRDIFF_MIN = %td\n", PTRDIFF_MIN);printf("PTRDIFF_MAX = %+td\n", PTRDIFF_MAX);printf("SIZE_MAX = %zu\n", SIZE_MAX);printf("SIG_ATOMIC_MIN = %+jd\n",(intmax_t)SIG_ATOMIC_MIN);printf("SIG_ATOMIC_MAX = %+jd\n",(intmax_t)SIG_ATOMIC_MAX);printf("WCHAR_MIN = %+jd\n",(intmax_t)WCHAR_MIN);printf("WCHAR_MAX = %+jd\n",(intmax_t)WCHAR_MAX);printf("WINT_MIN = %jd\n",(intmax_t)WINT_MIN);printf("WINT_MAX = %jd\n",(intmax_t)WINT_MAX);}
Possible output:
CHAR_BIT = 8MB_LEN_MAX = 16 CHAR_MIN = -128CHAR_MAX = +127SCHAR_MIN = -128SCHAR_MAX = +127UCHAR_MAX = 255 SHRT_MIN = -32768SHRT_MAX = +32767USHRT_MAX = 65535 INT_MIN = -2147483648INT_MAX = +2147483647UINT_MAX = 4294967295 LONG_MIN = -9223372036854775808LONG_MAX = +9223372036854775807ULONG_MAX = 18446744073709551615 LLONG_MIN = -9223372036854775808LLONG_MAX = +9223372036854775807ULLONG_MAX = 18446744073709551615 PTRDIFF_MIN = -9223372036854775808PTRDIFF_MAX = +9223372036854775807SIZE_MAX = 18446744073709551615SIG_ATOMIC_MIN = -2147483648SIG_ATOMIC_MAX = +2147483647WCHAR_MIN = -2147483648WCHAR_MAX = +2147483647WINT_MIN = 0WINT_MAX = 4294967295
Defined in header <float.h> | |
FLT_RADIX | the radix (integer base) used by the representation of all three floating-point types (macro constant) |
DECIMAL_DIG (C99) | conversion fromlongdouble to decimal with at leastDECIMAL_DIG digits and back tolongdouble is the identity conversion: this is the decimal precision required to serialize/deserialize alongdouble(macro constant) |
FLT_DECIMAL_DIGDBL_DECIMAL_DIGLDBL_DECIMAL_DIG (C11) | conversion fromfloat/double/longdouble to decimal with at leastFLT_DECIMAL_DIG/DBL_DECIMAL_DIG/LDBL_DECIMAL_DIG digits and back is the identity conversion: this is the decimal precision required to serialize/deserialize a floating-point value. Defined to at least6,10, and10 respectively, or9 for IEEE float and17 for IEEE double (see also the C++ analog:max_digits10)(macro constant) |
FLT_MINDBL_MINLDBL_MIN | minimum, normalized, positive value offloat,double andlongdouble respectively (macro constant) |
FLT_TRUE_MINDBL_TRUE_MINLDBL_TRUE_MIN (C11) | minimum positive value offloat,double andlongdouble respectively (macro constant) |
FLT_MAXDBL_MAXLDBL_MAX | maximum finite value offloat,double andlongdouble respectively (macro constant) |
FLT_EPSILONDBL_EPSILONLDBL_EPSILON | absolute value difference between1.0 and the next representable value forfloat,double andlongdouble respectively (macro constant) |
FLT_DIGDBL_DIGLDBL_DIG | number of decimal digits that are guaranteed to be preserved in text →float/double/longdouble → text roundtrip without change due to rounding or overflow (see the C++ analogdigits10 for detail)(macro constant) |
FLT_MANT_DIGDBL_MANT_DIGLDBL_MANT_DIG | number of base-FLT_RADIX digits that are in the floating-point mantissa and that can be represented without losing precision forfloat,double andlongdouble respectively(macro constant) |
FLT_MIN_EXPDBL_MIN_EXPLDBL_MIN_EXP | minimum negative integer such thatFLT_RADIX raised by power one less than that integer is a normalizedfloat,double andlongdouble respectively(macro constant) |
FLT_MIN_10_EXPDBL_MIN_10_EXPLDBL_MIN_10_EXP | minimum negative integer such that 10 raised to that power is a normalizedfloat,double andlongdouble respectively (macro constant) |
FLT_MAX_EXPDBL_MAX_EXPLDBL_MAX_EXP | maximum positive integer such thatFLT_RADIX raised by power one less than that integer is a representable finitefloat,double andlongdouble respectively(macro constant) |
FLT_MAX_10_EXPDBL_MAX_10_EXPLDBL_MAX_10_EXP | maximum positive integer such that 10 raised to that power is a representable finitefloat,double andlongdouble respectively (macro constant) |
| rounding mode of floating-point arithmetic (macro constant) | |
(C99) | specifies in what precision all arithmetic operations are done (macro constant) |
FLT_HAS_SUBNORMDBL_HAS_SUBNORMLDBL_HAS_SUBNORM (C11)(deprecated in C23) | whether the type supports subnormal (denormal) numbers: -1 – indeterminable,0 – absent,1 – present (macro constant) |
#include <float.h>#include <math.h>#include <stdio.h> int main(void){printf("DECIMAL_DIG = %d\n", DECIMAL_DIG);printf("FLT_DECIMAL_DIG = %d\n", FLT_DECIMAL_DIG);printf("FLT_RADIX = %d\n", FLT_RADIX);printf("FLT_MIN = %e\n", FLT_MIN);printf("FLT_MAX = %e\n", FLT_MAX);printf("FLT_EPSILON = %e\n", FLT_EPSILON);printf("FLT_DIG = %d\n", FLT_DIG);printf("FLT_MANT_DIG = %d\n", FLT_MANT_DIG);printf("FLT_MIN_EXP = %d\n", FLT_MIN_EXP);printf("FLT_MIN_10_EXP = %d\n", FLT_MIN_10_EXP);printf("FLT_MAX_EXP = %d\n", FLT_MAX_EXP);printf("FLT_MAX_10_EXP = %d\n", FLT_MAX_10_EXP);printf("FLT_ROUNDS = %d\n",FLT_ROUNDS);printf("FLT_EVAL_METHOD = %d\n",FLT_EVAL_METHOD);printf("FLT_HAS_SUBNORM = %d\n", FLT_HAS_SUBNORM);}
Possible output:
DECIMAL_DIG = 37FLT_DECIMAL_DIG = 9FLT_RADIX = 2FLT_MIN = 1.175494e-38FLT_MAX = 3.402823e+38FLT_EPSILON = 1.192093e-07FLT_DIG = 6FLT_MANT_DIG = 24FLT_MIN_EXP = -125FLT_MIN_10_EXP = -37FLT_MAX_EXP = 128FLT_MAX_10_EXP = 38FLT_ROUNDS = 1FLT_EVAL_METHOD = 1FLT_HAS_SUBNORM = 1
C++ documentation forC numeric limits interface |