이름공간
변수
행위

std::numeric_limits

cppreference.com
< cpp‎ | types
 
 
 
Type support
Type properties
(C++11)
(C++11)
(C++11)
Supported operations
Relationships and property queries
(C++11)
(C++11)
(C++11)
(C++11)
Type modifications
Type transformations
(C++11)
(C++11)
Type trait constants
 
 
<limits> 에 정의되어 있음.
template<class T >class numeric_limits;

numeric_limits 클래스 템플릿은 산술형의 다양한 속성을 조회할 수 있는 표준화된 방법을 제공한다. (예컨데 int형이 가질 수 있는 최댓값은 std::numeric_limits<int>::max()이다).

이 정보는 numeric_limits 템플릿의 특수화를 통해 얻어진다. 표준 라이브러리는 모든 산술형에 대한 특수화를 제공한다.:

<limits> 에 정의되어 있음.
template<>class numeric_limits<bool>;

template<>class numeric_limits<char>;
template<>class numeric_limits<signedchar>;
template<>class numeric_limits<unsignedchar>;
template<>class numeric_limits<wchar_t>;
template<>class numeric_limits<char16_t>;   // C++11 기능
template<>class numeric_limits<char32_t>;   // C++11 기능
template<>class numeric_limits<short>;
template<>class numeric_limits<unsignedshort>;
template<>class numeric_limits<int>;
template<>class numeric_limits<unsignedint>;
template<>class numeric_limits<long>;
template<>class numeric_limits<unsignedlong>;
template<>class numeric_limits<longlong>;
template<>class numeric_limits<unsignedlonglong>;
template<>class numeric_limits<float>;
template<>class numeric_limits<double>;

template<>class numeric_limits<longdouble>;

Additionally, a specialization exists for every cv-qualified version of each arithmetic type, identical to the unqualified specialization, e.g. std::numeric_limits<const int>, std::numeric_limits<volatile int>, and std::numeric_limits<const volatile int> are provided and are equivalent to std::numeric_limits<int>.

The standard library types that are aliases of arithmetic types (such as std::size_t or std::streamsize) may also be examined with the std::numeric_limits type traits.

Non-arithmetic standard types, such as std::complex<T> or std::nullptr_t, do not have specializations.

Implementations may provide specializations of std::numeric_limits for implementation-specific types: e.g. GCC provides std::numeric_limits<__int128>. Non-standard libraries may add specializations for library-provided types, e.g. OpenEXR provides std::numeric_limits<half> for a 16-bit floating-point type.

목차

[편집]Template parameters

T - a type to retrieve numeric properties for

[편집]Member constants

identifies types for which std::numeric_limits is specialized
(public static member constant)[edit]
[static]
identifies signed types
(public static member constant)[edit]
[static]
identifies integer types
(public static member constant)[edit]
[static]
identifies exact types
(public static member constant)[edit]
identifies floating-point types that can represent the special value "positive infinity"
(public static member constant)[edit]
identifies floating-point types that can represent the special value "quiet not-a-number" (NaN)
(public static member constant)[edit]
identifies floating-point types that can represent the special value "signaling not-a-number" (NaN)
(public static member constant)[edit]
[static]
identifies the denormalization style used by the floating-point type
(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]
[static]
identifies the rounding style used by the type
(public static member constant)[edit]
[static]
identifies the IEC 559/IEEE 754 floating-point types
(public static member constant)[edit]
[static]
identifies types that represent a finite set of values
(public static member constant)[edit]
[static]
identifies types that handle overflows with modulo arithmetic
(public static member constant)[edit]
[static]
number of radix digits that can be represented without change
(public static member constant)[edit]
[static]
number of decimal digits that can be represented without change
(public static member constant)[edit]
[static](C++11)
number of decimal digits necessary to differentiate all values of this type
(public static member constant)[edit]
[static]
the radix or integer base used by the representation of the given type
(public static member constant)[edit]
one more than the smallest negative power of the radix that is a valid normalized floating-point value
(public static member constant)[edit]
the smallest negative power of ten that is a valid normalized floating-point value
(public static member constant)[edit]
one more than the largest integer power of the radix that is a valid finite floating-point value
(public static member constant)[edit]
the largest integer power of 10 that is a valid finite floating-point value
(public static member constant)[edit]
[static]
identifies types which can cause arithmetic operations to trap
(public static member constant)[edit]
identifies floating-point types that detect tinyness before rounding
(public static member constant)[edit]

[편집]Member functions

[static]
returns the smallest finite value of the given type
(public static member function)[edit]
[static](C++11)
returns the lowest finite value of the given type
(public static member function)[edit]
[static]
returns the largest finite value of the given type
(public static member function)[edit]
[static]
returns the difference between 1.0 and the next representable value of the given floating-point type
(public static member function)[edit]
[static]
returns the maximum rounding error of the given floating-point type
(public static member function)[edit]
[static]
returns the positive infinity value of the given floating-point type
(public static member function)[edit]
[static]
returns a quiet NaN value of the given floating-point type
(public static member function)[edit]
returns a signaling NaN value of the given floating-point type
(public static member function)[edit]
[static]
returns the smallest positive subnormal value of the given floating-point type
(public static member function)[edit]

[편집]Helper classes

indicates floating-point rounding modes
(enum)[edit]
indicates floating-point denormalization modes
(enum)[edit]

[편집]Relationship with C library macro constants

Specialization Members
min()lowest()
(C++11)
max()epsilon()digitsdigits10min_exponentmin_exponent10max_exponentmax_exponent10radix
numeric_limits< bool >2
numeric_limits< char >CHAR_MINCHAR_MINCHAR_MAX2
numeric_limits< signedchar >SCHAR_MINSCHAR_MINSCHAR_MAX2
numeric_limits< unsignedchar >00UCHAR_MAX2
numeric_limits< wchar_t >WCHAR_MINWCHAR_MINWCHAR_MAX2
numeric_limits< char16_t >00UINT_LEAST16_MAX2
numeric_limits< char32_t >00UINT_LEAST32_MAX2
numeric_limits< short >SHRT_MINSHRT_MINSHRT_MAX2
numeric_limits< signedshort >
numeric_limits< unsignedshort >00USHRT_MAX2
numeric_limits< int >INT_MININT_MININT_MAX2
numeric_limits< signedint >
numeric_limits< unsignedint >00UINT_MAX2
numeric_limits< long >LONG_MINLONG_MINLONG_MAX2
numeric_limits< signedlong >
numeric_limits< unsignedlong >00ULONG_MAX2
numeric_limits< longlong >LLONG_MINLLONG_MINLLONG_MAX2
numeric_limits< signedlonglong >
numeric_limits< unsignedlonglong >00ULLONG_MAX2
numeric_limits< float >FLT_MIN-FLT_MAXFLT_MAXFLT_EPSILONFLT_MANT_DIGFLT_DIGFLT_MIN_EXPFLT_MIN_10_EXPFLT_MAX_EXPFLT_MAX_10_EXPFLT_RADIX
numeric_limits< double >DBL_MIN-DBL_MAXDBL_MAXDBL_EPSILONDBL_MANT_DIGDBL_DIGDBL_MIN_EXPDBL_MIN_10_EXPDBL_MAX_EXPDBL_MAX_10_EXPFLT_RADIX
numeric_limits< longdouble >LDBL_MIN-LDBL_MAXLDBL_MAXLDBL_EPSILONLDBL_MANT_DIGLDBL_DIGLDBL_MIN_EXPLDBL_MIN_10_EXPLDBL_MAX_EXPLDBL_MAX_10_EXPFLT_RADIX

[편집]Example

#include <limits>#include <iostream>   int main(){std::cout<<"type\tlowest\thighest\n";std::cout<<"int\t"<< std::numeric_limits<int>::lowest()<<'\t'<< std::numeric_limits<int>::max()<<'\n';std::cout<<"float\t"<< std::numeric_limits<float>::lowest()<<'\t'<< std::numeric_limits<float>::max()<<'\n';std::cout<<"double\t"<< std::numeric_limits<double>::lowest()<<'\t'<< std::numeric_limits<double>::max()<<'\n';}

Possible output:

type lowest highest int -2147483648 2147483647 float -3.40282e+38 3.40282e+38 double -1.79769e+308 1.79769e+308

[편집]See also

close