Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::numeric_limits<T>::traps

      From cppreference.com
      <cpp‎ |types‎ |numeric limits
       
       
      Utilities library
       
       
      std::numeric_limits
      Static constants
      numeric_limits::traps
      Static member functions
      Helper types
       
      staticconstbool traps;
      (until C++11)
      staticconstexprbool traps;
      (since C++11)

      The value ofstd::numeric_limits<T>::traps istrue for all arithmetic typesT that have at least one value at the start of the program that, if used as an argument to an arithmetic operation, will generate atrap.

      Contents

      [edit]Standard specializations

      T value ofstd::numeric_limits<T>::traps
      /* non-specialized */false
      boolfalse
      char usuallytrue
      signedchar usuallytrue
      unsignedchar usuallytrue
      wchar_t usuallytrue
      char8_t(since C++20) usuallytrue
      char16_t(since C++11) usuallytrue
      char32_t(since C++11) usuallytrue
      short usuallytrue
      unsignedshort usuallytrue
      int usuallytrue
      unsignedint usuallytrue
      long usuallytrue
      unsignedlong usuallytrue
      longlong(since C++11) usuallytrue
      unsignedlonglong(since C++11) usuallytrue
      float usuallyfalse
      double usuallyfalse
      longdouble usuallyfalse

      [edit]Notes

      On most platforms integer division by zero always traps, andstd::numeric_limits<T>::traps istrue for all integer types that support the value0. The exception is the typebool: even though division byfalse traps due to integral promotion frombool toint, it is the zero-valuedint that traps. Zero is not a value of typebool.

      On most platforms, floating-point exceptions may be turned on and off at run time (e.g.feenableexcept() on Linux or_controlfp on Windows), in which case the value ofstd::numeric_limits<T>::traps for floating-point types reflects the state of floating-point trapping facility at the time of program startup, which isfalse on most modern systems. An exception would be aDEC Alpha program, where it istrue if compiled without-ieee.

      [edit]Example

      Run this code
      #include <iostream>#include <limits> int main(){std::cout<<std::boolalpha<<"bool:     traps = "<<std::numeric_limits<bool>::traps<<'\n'<<"char:     traps = "<<std::numeric_limits<char>::traps<<'\n'<<"char16_t: traps = "<<std::numeric_limits<char16_t>::traps<<'\n'<<"long:     traps = "<<std::numeric_limits<long>::traps<<'\n'<<"float:    traps = "<<std::numeric_limits<float>::traps<<'\n';}

      Possible output:

      // GCC output:bool:     traps = truechar:     traps = truechar16_t: traps = truelong:     traps = truefloat:    traps = false // Clang output:bool:     traps = falsechar:     traps = truechar16_t: traps = truelong:     traps = truefloat:    traps = false

      [edit]Defect reports

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

      DRApplied toBehavior as publishedCorrect behavior
      LWG 497C++98it was unclear what is returned if trapping
      is enabled or disabled at runtime
      returns the enable status
      at the start of the program

      [edit]See also

      Floating-point environment
      identifies floating-point types that detect tinyness before rounding
      (public static member constant)[edit]
      identifies the floating-point types that detect loss of precision as denormalization loss rather than inexact result
      (public static member constant)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/types/numeric_limits/traps&oldid=148550"

      [8]ページ先頭

      ©2009-2025 Movatter.jp