Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      C numeric limits interface

      From cppreference.com
      <cpp‎ |types
       
       
      Utilities library
       
      Type support
      Basic types
      Fixed width integer types(C++11)
      Fixed width floating-point types(C++23)
      (C++11)    
      (C++17)
      Numeric limits
      C numeric limits interface
      Runtime type information
       

      See alsostd::numeric_limits interface.

      Contents

      [edit]Limits of integer types

      Limits of core language integer types
      Defined in header<climits>
      CHAR_BIT
      bit width of byte
      (macro constant)[edit]
      MB_LEN_MAX
      maximum number of bytes in a multibyte character
      (macro constant)[edit]
      CHAR_MIN
      minimum value ofchar
      (macro constant)[edit]
      CHAR_MAX
      maximum value ofchar
      (macro constant)[edit]
      SCHAR_MINSHRT_MININT_MINLONG_MINLLONG_MIN
      (C++11)
      minimum value ofsignedchar,short,int,long andlonglong respectively
      (macro constant)[edit]
      SCHAR_MAXSHRT_MAXINT_MAXLONG_MAXLLONG_MAX
      (C++11)
      maximum value ofsignedchar,short,int,long andlonglong respectively
      (macro constant)[edit]
      UCHAR_MAXUSHRT_MAXUINT_MAXULONG_MAXULLONG_MAX
      (C++11)
      maximum value ofunsignedchar,unsignedshort,unsignedint,
      unsignedlong andunsignedlonglong respectively
      (macro constant)[edit]
      Defined in header<cwchar>
      Defined in header<cstdint>
      WCHAR_MIN
      (C++11)
      minimum value ofwchar_t
      (macro constant)[edit]
      WCHAR_MAX
      (C++11)
      maximum value ofwchar_t
      (macro constant)[edit]
      Limits of library type aliases
      Defined in header<cstdint>
      PTRDIFF_MIN
      (C++11)
      minimum value ofstd::ptrdiff_t
      (macro constant)[edit]
      PTRDIFF_MAX
      (C++11)
      maximum value ofstd::ptrdiff_t
      (macro constant)[edit]
      SIZE_MAX
      (C++11)
      maximum value ofstd::size_t
      (macro constant)[edit]
      SIG_ATOMIC_MIN
      (C++11)
      minimum value ofstd::sig_atomic_t
      (macro constant)[edit]
      SIG_ATOMIC_MAX
      (C++11)
      maximum value ofstd::sig_atomic_t
      (macro constant)[edit]
      WINT_MIN
      (C++11)
      minimum value ofstd::wint_t
      (macro constant)[edit]
      WINT_MAX
      (C++11)
      maximum value ofstd::wint_t
      (macro constant)[edit]

      [edit]Notes

      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.

      Afreestanding implementation may lackstd::sig_atomic_t and/orstd::wint_t typedef names, in which case theSIG_ATOMIC_* and/orWINT_* macros are correspondingly absent.

      [edit]Example

      Run this code
      #include <climits>#include <cstdint>#include <iomanip>#include <iostream> int main(){constexprint w=14;std::cout<<std::left;#   define COUT(x) std::cout << std::setw(w) << #x << " = " << x << '\n'     COUT( CHAR_BIT);    COUT( MB_LEN_MAX);    COUT( CHAR_MIN);    COUT( CHAR_MAX);    COUT( SCHAR_MIN);    COUT( SHRT_MIN);    COUT( INT_MIN);    COUT( LONG_MIN);    COUT( LLONG_MIN);    COUT( SCHAR_MAX);    COUT( SHRT_MAX);    COUT( INT_MAX);    COUT( LONG_MAX);    COUT( LLONG_MAX);    COUT( UCHAR_MAX);    COUT( USHRT_MAX);    COUT( UINT_MAX);    COUT( ULONG_MAX);    COUT( ULLONG_MAX);    COUT( PTRDIFF_MIN);    COUT( PTRDIFF_MAX);    COUT( SIZE_MAX);    COUT( SIG_ATOMIC_MIN);    COUT( SIG_ATOMIC_MAX);    COUT( WCHAR_MIN);    COUT( WCHAR_MAX);    COUT( WINT_MIN);    COUT( WINT_MAX);}

      Possible output:

      CHAR_BIT       = 8MB_LEN_MAX     = 16CHAR_MIN       = -128CHAR_MAX       = 127SCHAR_MIN      = -128SHRT_MIN       = -32768INT_MIN        = -2147483648LONG_MIN       = -9223372036854775808LLONG_MIN      = -9223372036854775808SCHAR_MAX      = 127SHRT_MAX       = 32767INT_MAX        = 2147483647LONG_MAX       = 9223372036854775807LLONG_MAX      = 9223372036854775807UCHAR_MAX      = 255USHRT_MAX      = 65535UINT_MAX       = 4294967295ULONG_MAX      = 18446744073709551615ULLONG_MAX     = 18446744073709551615PTRDIFF_MIN    = -9223372036854775808PTRDIFF_MAX    = 9223372036854775807SIZE_MAX       = 18446744073709551615SIG_ATOMIC_MIN = -2147483648SIG_ATOMIC_MAX = 2147483647WCHAR_MIN      = -2147483648WCHAR_MAX      = 2147483647WINT_MIN       = 0WINT_MAX       = 4294967295

      [edit]Limits of floating-point types

      Defined in header<cfloat>
      FLT_RADIX
      the radix (integer base) used by the representation of all three floating-point types
      (macro constant)[edit]
      DECIMAL_DIG
      (C++11)
      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 (see alsostd::numeric_limits::max_digits10)
      (macro constant)[edit]
      FLT_DECIMAL_DIGDBL_DECIMAL_DIGLDBL_DECIMAL_DIG
      (C++17)
      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 (see alsostd::numeric_limits::max_digits10). Defined to at least6,10, and10 respectively, or9 for IEEE float and17 for IEEE double.
      (macro constant)[edit]
      FLT_MINDBL_MINLDBL_MIN
      minimum normalized positive value offloat,double andlongdouble respectively
      (macro constant)[edit]
      FLT_TRUE_MINDBL_TRUE_MINLDBL_TRUE_MIN
      (C++17)
      minimum positive value offloat,double andlongdouble respectively
      (macro constant)[edit]
      FLT_MAXDBL_MAXLDBL_MAX
      maximum finite value offloat,double andlongdouble respectively
      (macro constant)[edit]
      FLT_EPSILONDBL_EPSILONLDBL_EPSILON
      difference between1.0 and the next representable value forfloat,double andlongdouble respectively
      (macro constant)[edit]
      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 (seestd::numeric_limits::digits10 for explanation)
      (macro constant)[edit]
      FLT_MANT_DIGDBL_MANT_DIGLDBL_MANT_DIG
      number of baseFLT_RADIX digits that can be represented without losing precision forfloat,double andlongdouble respectively
      (macro constant)[edit]
      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)[edit]
      FLT_MIN_10_EXPDBL_MIN_10_EXPLDBL_MIN_10_EXP
      minimum negative integer such that10 raised to that power is a normalizedfloat,double andlongdouble respectively
      (macro constant)[edit]
      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)[edit]
      FLT_MAX_10_EXPDBL_MAX_10_EXPLDBL_MAX_10_EXP
      maximum positive integer such that10 raised to that power is a representable finitefloat,double andlongdouble respectively
      (macro constant)[edit]
      default rounding mode of floating-point arithmetic
      (macro constant)[edit]
      specifies in what precision all arithmetic operations are done
      (macro constant)[edit]
      FLT_HAS_SUBNORMDBL_HAS_SUBNORMLDBL_HAS_SUBNORM
      (C++17)
      specifies whether the type supports subnormal (denormal) numbers:
      -1 – indeterminable,0 – absent,1 – present
      (macro constant)[edit]

      [edit]Example

      Run this code
      #include <cfloat>#include <iomanip>#include <iostream> int main(){int w=16;std::cout<<std::left;// std::cout << std::setprecision(53);#   define COUT(x) std::cout << std::setw(w) << #x << " = " << x << '\n'     COUT( FLT_RADIX);    COUT( DECIMAL_DIG);    COUT( FLT_DECIMAL_DIG);    COUT( DBL_DECIMAL_DIG);    COUT( LDBL_DECIMAL_DIG);    COUT( FLT_MIN);    COUT( DBL_MIN);    COUT( LDBL_MIN);    COUT( FLT_TRUE_MIN);    COUT( DBL_TRUE_MIN);    COUT( LDBL_TRUE_MIN);    COUT( FLT_MAX);    COUT( DBL_MAX);    COUT( LDBL_MAX);    COUT( FLT_EPSILON);    COUT( DBL_EPSILON);    COUT( LDBL_EPSILON);    COUT( FLT_DIG);    COUT( DBL_DIG);    COUT( LDBL_DIG);    COUT( FLT_MANT_DIG);    COUT( DBL_MANT_DIG);    COUT( LDBL_MANT_DIG);    COUT( FLT_MIN_EXP);    COUT( DBL_MIN_EXP);    COUT( LDBL_MIN_EXP);    COUT( FLT_MIN_10_EXP);    COUT( DBL_MIN_10_EXP);    COUT( LDBL_MIN_10_EXP);    COUT( FLT_MAX_EXP);    COUT( DBL_MAX_EXP);    COUT( LDBL_MAX_EXP);    COUT( FLT_MAX_10_EXP);    COUT( DBL_MAX_10_EXP);    COUT( LDBL_MAX_10_EXP);    COUT(FLT_ROUNDS);    COUT(FLT_EVAL_METHOD);    COUT( FLT_HAS_SUBNORM);    COUT( DBL_HAS_SUBNORM);    COUT( LDBL_HAS_SUBNORM);}

      Possible output:

      FLT_RADIX        = 2DECIMAL_DIG      = 21FLT_DECIMAL_DIG  = 9DBL_DECIMAL_DIG  = 17LDBL_DECIMAL_DIG = 21FLT_MIN          = 1.17549e-38DBL_MIN          = 2.22507e-308LDBL_MIN         = 3.3621e-4932FLT_TRUE_MIN     = 1.4013e-45DBL_TRUE_MIN     = 4.94066e-324LDBL_TRUE_MIN    = 3.6452e-4951FLT_MAX          = 3.40282e+38DBL_MAX          = 1.79769e+308LDBL_MAX         = 1.18973e+4932FLT_EPSILON      = 1.19209e-07DBL_EPSILON      = 2.22045e-16LDBL_EPSILON     = 1.0842e-19FLT_DIG          = 6DBL_DIG          = 15LDBL_DIG         = 18FLT_MANT_DIG     = 24DBL_MANT_DIG     = 53LDBL_MANT_DIG    = 64FLT_MIN_EXP      = -125DBL_MIN_EXP      = -1021LDBL_MIN_EXP     = -16381FLT_MIN_10_EXP   = -37DBL_MIN_10_EXP   = -307LDBL_MIN_10_EXP  = -4931FLT_MAX_EXP      = 128DBL_MAX_EXP      = 1024LDBL_MAX_EXP     = 16384FLT_MAX_10_EXP   = 38DBL_MAX_10_EXP   = 308LDBL_MAX_10_EXP  = 4932FLT_ROUNDS       = 1FLT_EVAL_METHOD  = 0FLT_HAS_SUBNORM  = 1DBL_HAS_SUBNORM  = 1LDBL_HAS_SUBNORM = 1

      [edit]Defect reports

      The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

      DRApplied toBehavior as publishedCorrect behavior
      LWG 416C++98it was unclear whether the types of the macros in<climits> are guaranteed
      to match the type to which they refer (C++ refers to C, and C says no)
      clarified as not
      guaranteed

      [edit]See also

      C documentation forNumeric limits
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/types/climits&oldid=167902"

      [8]ページ先頭

      ©2009-2025 Movatter.jp