Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::numeric_limits<T>::min

      From cppreference.com
      <cpp‎ |types‎ |numeric limits
       
       
      Utilities library
       
       
      std::numeric_limits
      Static constants
      Static member functions
      numeric_limits::min
      Helper types
       
      Defined in header<limits>
      static T min()throw();
      (until C++11)
      staticconstexpr T min()noexcept;
      (since C++11)

      Returns the minimum finite value representable by the numeric typeT.

      For floating-point types with denormalization,min() returns the minimum positive normalized value.Note that this behavior may be unexpected, especially when compared to the behavior ofmin() for integral types.To find the value that has no values less than it, uselowest().(since C++11)

      min() is only meaningful for bounded types and for unbounded unsigned types.

      [edit]Return value

      Tstd::numeric_limits<T>::min()
      /* non-specialized */T()
      boolfalse
      charCHAR_MIN
      signedcharSCHAR_MIN
      unsignedchar0
      wchar_tWCHAR_MIN
      char8_t(since C++20)0
      char16_t(since C++11)0
      char32_t(since C++11)0
      shortSHRT_MIN
      unsignedshort0
      intINT_MIN
      unsignedint0
      longLONG_MIN
      unsignedlong0
      longlong(since C++11)LLONG_MIN
      unsignedlonglong(since C++11)0
      floatFLT_MIN
      doubleDBL_MIN
      longdoubleLDBL_MIN

      [edit]Example

      Demonstrates the use with typedef types, and the difference in the sign of the result between integer and floating-point types:

      Run this code
      #include <cstddef>#include <iomanip>#include <iostream>#include <limits> // we want to print char types as an integer without leading Fsauto p(auto x){return x;}auto p(char x){return x&static_cast<unsignedchar>(-1);} template<typename T>void print_one(std::string_view type_name){constexpr T min=std::numeric_limits<T>::min(); std::cout<<std::dec<<std::defaultfloat<<std::setw(14)<< type_name<<" ("<<std::setw(2)<< sizeof(T)<<" bytes): "<<+min; ifconstexpr(min!=0)std::cout<<" or "<<std::showbase<<std::hex<<std::hexfloat<< p(min); std::cout<<'\n';} #define SHOW(T) print_one<T>(#T) int main(){    SHOW(bool);    SHOW(char);    SHOW(unsignedchar);    SHOW(short);    SHOW(unsignedshort);    SHOW(signed);    SHOW(unsigned);    SHOW(std::ptrdiff_t);    SHOW(std::size_t);    SHOW(float);    SHOW(double);    SHOW(longdouble);}

      Possible output:

                bool ( 1 bytes): 0          char ( 1 bytes): -128 or 0x80 unsigned char ( 1 bytes): 0         short ( 2 bytes): -32768 or 0x8000unsigned short ( 2 bytes): 0        signed ( 4 bytes): -2147483648 or 0x80000000      unsigned ( 4 bytes): 0std::ptrdiff_t ( 8 bytes): -9223372036854775808 or 0x8000000000000000   std::size_t ( 8 bytes): 0         float ( 4 bytes): 1.17549e-38 or 0x1p-126        double ( 8 bytes): 2.22507e-308 or 0x1p-1022   long double (16 bytes): 3.3621e-4932 or 0x8p-16385

      [edit]See also

      [static](C++11)
      returns the lowest finite value of the given type, i.e. the most negative value for signed types,0 for unsigned types
      (public static member function)[edit]
      [static]
      returns the smallest positive subnormal value of the given floating-point type
      (public static member function)[edit]
      [static]
      returns the largest finite value of the given type
      (public static member function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/types/numeric_limits/min&oldid=178130"

      [8]ページ先頭

      ©2009-2025 Movatter.jp