C Numerical Limit Interface
See std::numeric_limits interface
Defined in the header file |
|
PTRDIFF_MIN (C++11) |
The minimum value of std::ptrdiff_t type object (Macro constant) |
PTRDIFF_MAX (C++11) |
The maximum value of std::ptrdiff_t type object (Macro constant) |
SIZE_MAX (C++11) |
The maximum value of std::size_t type object (Macro constant) |
SIG_ATOMIC_MIN (C++11) |
The minimum value of std::sig_atomic_t type object (Macro constant) |
SIG_ATOMIC_MAX (C++11) |
The maximum value of std::sig_atomic_t type object (Macro constant) |
WCHAR_MIN (C++11) |
Minimum value of wchar_t type object (Macro constant) |
WCHAR_MAX (C++11) |
Maximum value of wchar_t type object (Macro constant) |
WINT_MIN (C++11) |
The minimum value of std::wint_t type object (Macro constant) |
WINT_MAX (C++11) |
The maximum value of std::wint_t type object (Macro constant) |
Integer type limits
Defined in the header file |
|
CHAR_BIT |
Number of bytes (Macro constant) |
MB_LEN_MAX |
Maximum number of bytes for multi-byte characters (Macro constant) |
CHAR_MIN |
Minimum value of char (Macro constant) |
CHAR_MAX |
The maximum value of char (Macro constant) |
SCHAR_MINSHRT_MININT_MINLONG_MINLLONG_MIN (C++11) |
The minimum values of signed char, short, int, long and long long respectively (Macro constant) |
SCHAR_MAXSHRT_MAXINT_MAXLONG_MAXLLONG_MAX (C++11) |
The maximum values of signed char, short, int, long and long long respectively (Macro constant) |
UCHAR_MAXUSHRT_MAXUINT_MAXULONG_MAXULLONG_MAX (C++11) |
respectively unsigned char, unsigned short, unsigned int, The maximum value of unsigned long and unsigned long long (Macro constant) |
NOTE: These constants, except CHAR_BIT
and MB_LEN_MAX
, require that their types match the results of integer promotion, as applied to objects of the type they describe: CHAR_MAX
may have type int or unsigned int, but never char. Likewise USHRT_MAX
may not have an unsigned type: its type may be int .
Floating point type limit
Defined in header file |
|
FLT_RADIX |
The base (integer base) used for the representation of all three floating point types (Macro constant) |
DECIMAL_DIG (C++11) |
Convert from long double to decimal representation with at least DECIMAL_DIG digits, and then convert back to long double as identity Conversion: This is the decimal precision required to serialize/deserialize long double (see std::numeric_limits::max_digits10)(Macro constant) |
FLT_DECIMAL_DIGDBL_DECIMAL_DIGLDBL_DECIMAL_DIG (C++17) |
Convert from float/double/long double to at least FLT_DECIMAL_DIG /DBL_DECIMAL_DIG / LDBL_DECIMAL_DIG Decimal digits, converted back to the original type for identity conversion: this is the decimal precision required to serialize/deserialize floating point values (see std::numeric_limits::max_digits10). Defined to be at least 6, 10 and 10 respectively, 9 for IEEE float and 17 for IEEE double.(Macro constant) |
FLT_MINDBL_MINLDBL_MIN |
The minimum normalized positive values of float, double and long double respectively (Macro constant) |
FLT_TRUE_MINDBL_TRUE_MINLDBL_TRUE_MIN (C++17) |
The minimum positive values of float, double and long double respectively (Macro constant) |
FLT_MAXDBL_MAXLDBL_MAX |
The maximum values of float, double and long double respectively (Macro constant) |
FLT_EPSILONDBL_EPSILONLDBL_EPSILON |
The difference between 1.0 and the next representable value of float, double and long double respectively (Macro constant) |
FLT_DIGDBL_DIGLDBL_DIG |
Guaranteed to be preserved in the round-trip conversion of text → float/double/long double → text without being changed due to rounding or overflow number of decimal digits (see std::numeric_limits::digits10 for explanation) (Macro constant) |
FLT_MANT_DIGDBL_MANT_DIGLDBL_MANT_DIG |
The number of digits in the base FLT_RADIX that can be expressed as float, double and long double without loss of precision respectively.(Macro constant) |
FLT_MIN_EXPDBL_MIN_EXPLDBL_MIN_EXP |
Respectively, the integer of FLT_RADIX can be reduced to a power into a normalized float, double and long double. smallest negative integer(Macro constant) |
FLT_MIN_10_EXPDBL_MIN_10_EXPLDBL_MIN_10_EXP |
The smallest negative integers of float, double and long double that can reduce the integer of 10 to a power of 10 respectively. (Macro constant) |
FLT_MAX_EXPDBL_MAX_EXPLDBL_MAX_EXP |
Respectively, they are limited float, double and long that can reduce the integer of FLT_RADIX to a representable power. The largest positive integer of double(Macro constant) |
FLT_MAX_10_EXPDBL_MAX_10_EXPLDBL_MAX_10_EXP |
The maximum positive integer that can reduce the integer of 10 to a power that can be represented by limited float, double and long double respectively. (Macro constant) |
FLT_ROUNDS |
Default rounding mode for floating point arithmetic (Macro constant) |
FLT_EVAL_METHOD (C++11) |
Specifies the precision used for all arithmetic operations (Macro constant) |
FLT_HAS_SUBNORMDBL_HAS_SUBNORMLDBL_HAS_SUBNORM (C++17) |
Indicates whether the type supports non-normal values: -1 is uncertain, 0 is not supported, and 1 is supported. (Macro constant) |
Call example
#include <stdio.h> #include <stdint.h> #include <limits.h> #include <float.h> int main() { //Minimum value of std::ptrdiff_t type object printf("PTRDIFF_MIN: %d\\ ", PTRDIFF_MIN); //The maximum value of std::ptrdiff_t type object printf("PTRDIFF_MAX: %d\\ ", PTRDIFF_MAX); //The maximum value of std::size_t type object printf("SIZE_MAX: %d\\ ", SIZE_MAX); //Minimum value of std::sig_atomic_t type object printf("SIG_ATOMIC_MIN: %d\\ ", SIG_ATOMIC_MIN); //The maximum value of std::sig_atomic_t type object printf("SIG_ATOMIC_MAX: %d\\ ", SIG_ATOMIC_MAX); //Minimum value of wchar_t type object printf("WCHAR_MIN: %d\\ ", WCHAR_MIN); //Maximum value of wchar_t type object printf("WCHAR_MAX: %d\\ ", WCHAR_MAX); //Minimum value of std::wint_t type object printf("WINT_MIN: %d\\ ", WINT_MIN); //The maximum value of std::wint_t type object printf("WINT_MAX: %d\\ ", WINT_MAX); printf("\\ "); //integer type limit //number of bytes printf("CHAR_BIT: %d\\ ", CHAR_BIT); //Maximum number of bytes for multi-byte characters printf("MB_LEN_MAX: %d\\ ", MB_LEN_MAX); //Minimum value of char printf("CHAR_MIN: %d\\ ", CHAR_MIN); //Maximum value of char printf("CHAR_MAX: %d\\ ", CHAR_MAX); printf("\\ "); //The minimum values of signed char, short, int, long and long long respectively printf("SCHAR_MIN: %d\\ ", SCHAR_MIN); printf("SHRT_MIN: %d\\ ", SHRT_MIN); printf("INT_MIN: %d\\ ", INT_MIN); printf("LONG_MIN: %I32d\\ ", LONG_MIN); printf("LLONG_MIN: %I64d\\ ", LLONG_MIN); printf("\\ "); //The maximum values of signed char, short, int, long and long long respectively printf("SCHAR_MAX: %d\\ ", SCHAR_MAX); printf("SHRT_MAX: %d\\ ", SHRT_MAX); printf("INT_MAX: %d\\ ", INT_MAX); printf("LONG_MAX: %I32d\\ ", LONG_MAX); printf("LLONG_MAX: %I64d\\ ", LLONG_MAX); printf("\\ "); //respectively unsigned char, unsigned short, unsigned int, //The maximum value of unsigned long and unsigned long long printf("UCHAR_MAX: %d\\ ", UCHAR_MAX); printf("USHRT_MAX: %d\\ ", USHRT_MAX); printf("UINT_MAX: %d\\ ", UINT_MAX); printf("ULONG_MAX: %I32u\\ ", ULONG_MAX); printf("ULLONG_MAX: %I64u\\ ", ULLONG_MAX); printf("\\ "); //Floating point type limit //The base (integer base) used for the representation of all three floating point types printf("FLT_RADIX: %d\\ ", FLT_RADIX); //Convert from long double to decimal representation of at least DECIMAL_DIG digits, //Convert back to long double for identity conversion: this is the decimal precision required to serialize/deserialize long double // (see std::numeric_limits::max_digits10) printf("DECIMAL_DIG: %d\\ ", DECIMAL_DIG); printf("FLT_DECIMAL_DIG:%d\\ ", FLT_DECIMAL_DIG); printf("DBL_DECIMAL_DIG:%d\\ ", DBL_DECIMAL_DIG); printf("LDBL_DECIMAL_DIG:%d\\ ", LDBL_DECIMAL_DIG); printf("\\ "); //The minimum normalized positive values of float, double and long double respectively printf("FLT_MIN: %f\\ ", FLT_MIN); printf("DBL_MIN: %f\\ ", DBL_MIN); printf("LDBL_MIN: %lf\\ ", LDBL_MIN); printf("\\ "); //The minimum positive values for float, double and long double respectively printf("FLT_TRUE_MIN: %f\\ ", FLT_TRUE_MIN); printf("DBL_TRUE_MIN: %f\\ ", DBL_TRUE_MIN); printf("LDBL_TRUE_MIN: %lf\\ ", LDBL_TRUE_MIN); printf("\\ "); //The maximum values of float, double and long double respectively printf("FLT_MAX: %f\\ ", FLT_MAX); printf("DBL_MAX: %f\\ ", DBL_MAX); printf("LDBL_MAX: %lf\\ ", LDBL_MAX); printf("\\ "); //The difference between 1.0 and the next representable value of float, double and long double respectively printf("FLT_EPSILON: %f\\ ", FLT_EPSILON); printf("DBL_EPSILON: %f\\ ", DBL_EPSILON); printf("LDBL_EPSILON: %lf\\ ", LDBL_EPSILON); printf("\\ "); //Guaranteed to be preserved in round-trip conversions of text → float/double/long double → text without //The number of decimal digits changed due to rounding or overflow (see std::numeric_limits::digits10 for explanation) printf("FLT_DIG: %d\\ ", FLT_DIG); printf("DBL_DIG: %d\\ ", DBL_DIG); printf("LDBL_DIG: %d\\ ", LDBL_DIG); printf("\\ "); //The number of digits in the base FLT_RADIX that can be expressed as float, double and long double without loss of precision respectively. printf("FLT_MANT_DIG: %d\\ ", FLT_MANT_DIG); printf("DBL_MANT_DIG: %d\\ ", DBL_MANT_DIG); printf("LDBL_MANT_DIG:%d\\ ", LDBL_MANT_DIG); printf("\\ "); //The smallest negative integers that can reduce the integer of FLT_RADIX to the normalized power of float, double and long double respectively. printf("FLT_MIN_EXP: %d\\ ", FLT_MIN_EXP); printf("DBL_MIN_EXP: %d\\ ", DBL_MIN_EXP); printf("LDBL_MIN_EXP: %d\\ ", LDBL_MIN_EXP); printf("\\ "); //The smallest negative integers of float, double and long double that can reduce the integer of 10 to a power of 10 respectively. printf("FLT_MIN_10_EXP:%d\\ ", FLT_MIN_10_EXP); printf("DBL_MIN_10_EXP:%d\\ ", DBL_MIN_10_EXP); printf("LDBL_MIN_10_EXP:%d\\ ", LDBL_MIN_10_EXP); printf("\\ "); //Respectively, they are the largest positive integers that can reduce the integer of FLT_RADIX to a power that can be represented by limited float, double and long double. printf("FLT_MAX_EXP: %d\\ ", FLT_MAX_EXP); printf("DBL_MAX_EXP: %d\\ ", DBL_MAX_EXP); printf("LDBL_MAX_EXP: %d\\ ", LDBL_MAX_EXP); printf("\\ "); //Respectively, they are the largest positive integers that can reduce the integer of 10 to a power that can be represented by limited float, double and long double. printf("FLT_MAX_10_EXP: %d\\ ", FLT_MAX_10_EXP); printf("DBL_MAX_10_EXP: %d\\ ", DBL_MAX_10_EXP); printf("LDBL_MAX_10_EXP:%d\\ ", LDBL_MAX_10_EXP); printf("\\ "); //Default rounding mode for floating point arithmetic printf("FLT_ROUNDS: %d\\ ", FLT_ROUNDS); //Specify the precision to use for all arithmetic operations printf("FLT_EVAL_METHOD:%d\\ ", FLT_EVAL_METHOD); //Indicate whether the type supports informal values: -1 is uncertain, 0 is not supported, and 1 is supported. printf("FLT_HAS_SUBNORM:%d\\ ", FLT_HAS_SUBNORM); printf("DBL_HAS_SUBNORM:%d\\ ", DBL_HAS_SUBNORM); printf("LDBL_HAS_SUBNORM:%d\\ ", LDBL_HAS_SUBNORM); printf("\\ "); return 0; }
Output
PTRDIFF_MIN: -2147483648 PTRDIFF_MAX: 2147483647 SIZE_MAX: -1 SIG_ATOMIC_MIN: -2147483648 SIG_ATOMIC_MAX: 2147483647 WCHAR_MIN: 0 WCHAR_MAX: 65535 WINT_MIN: 0 WINT_MAX: 65535 CHAR_BIT: 8 MB_LEN_MAX: 5 CHAR_MIN: -128 CHAR_MAX: 127 SCHAR_MIN: -128 SHRT_MIN: -32768 INT_MIN: -2147483648 LONG_MIN: -2147483648 LLONG_MIN: -9223372036854775808 SCHAR_MAX: 127 SHRT_MAX: 32767 INT_MAX: 2147483647 LONG_MAX: 2147483647 LLONG_MAX: 9223372036854775807 UCHAR_MAX: 255 USHRT_MAX: 65535 UINT_MAX: -1 ULONG_MAX: 4294967295 ULLONG_MAX: 18446744073709551615 FLT_RADIX: 2 DECIMAL_DIG: 21 FLT_DECIMAL_DIG:9 DBL_DECIMAL_DIG:17 LDBL_DECIMAL_DIG:21 FLT_MIN: 0.000000 DBL_MIN: 0.000000 LDBL_MIN: -0.000000 FLT_TRUE_MIN: 0.000000 DBL_TRUE_MIN: 0.000000 LDBL_TRUE_MIN: 0.000000 FLT_MAX: 340282346638528860000000000000000000000.000000 DBL_MAX: 1797693134862315700000000000000000000000000000 0000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000 000000000000000000000000000000000.000000 LDBL_MAX: -1.#QNAN0 FLT_EPSILON: 0.000000 DBL_EPSILON: 0.000000 LDBL_EPSILON: -0.000000 FLT_DIG: 6 DBL_DIG: 15 LDBL_DIG: 18 FLT_MANT_DIG: 24 DBL_MANT_DIG: 53 LDBL_MANT_DIG:64 FLT_MIN_EXP: -125 DBL_MIN_EXP: -1021 LDBL_MIN_EXP: -16381 FLT_MIN_10_EXP:-37 DBL_MIN_10_EXP:-307 LDBL_MIN_10_EXP:-4931 FLT_MAX_EXP: 128 DBL_MAX_EXP: 1024 LDBL_MAX_EXP: 16384 FLT_MAX_10_EXP: 38 DBL_MAX_10_EXP: 308 LDBL_MAX_10_EXP:4932 FLT_ROUNDS: 1 FLT_EVAL_METHOD:2 FLT_HAS_SUBNORM:1 DBL_HAS_SUBNORM:1 LDBL_HAS_SUBNORM:1