oj mrJudge
Toggle navigation
  • Login
    • Forget Password
      Login
User Image

Hello, Stranger

Guest
  • Analysis Mode
  • Problems
    • All Problems
    • Latest Problems
  • Join Us Now
  • Registration
  • Contact Us
  • Infomation
  • C++ Reference
  • About
    • Help
    • Terms of Use
    • Technical Specifications
    • Credits

C++ Reference as of 28 May 2018

std::numeric_limits - cppreference.com

std::numeric_limits

From cppreference.com
< cpp‎ | types
 
C++
Language
Headers
Library concepts
Language support library
Diagnostics library
Utilities library
Strings library
Containers library
Algorithms library
Iterators library
Numerics library
Input/output library
Localizations library
Regular expressions library (C++11)
Atomic operations library (C++11)
Thread support library (C++11)
Filesystem library (C++17)
Technical Specifications
 
Utilities library
Type support (basic types, RTTI, type traits)
Dynamic memory management
Error handling
Program utilities
Variadic functions
Date and time
Function objects
initializer_list
(C++11)
bitset
hash
(C++11)
integer_sequence
(C++14)
Relational operators (deprecated)
rel_ops::operator!=rel_ops::operator>rel_ops::operator<=rel_ops::operator>=
Comparisons (C++20)
strong_order
weak_order
partial_order

strong_equal
weak_equal
strong_ordering
weak_ordering
partial_ordering

strong_equality
weak_equality
is_eqis_neqis_ltis_lteqis_gtis_gteq
common_comparison_category
Common vocabulary types
pair
tuple
(C++11)
apply
(C++17)
make_from_tuple
(C++17)
optional
(C++17)
any
(C++17)
variant
(C++17)

Swap, forward and move
swap
exchange
(C++14)
forward
(C++11)
move
(C++11)
move_if_noexcept
(C++11)
Elementary string conversions
to_chars
(C++17)
from_chars
(C++17)
chars_format
(C++17)
Type operations
declval
(C++11)
as_const
(C++17)
 
Type support
Basic types
Fundamental types
Fixed width integer types (C++11)
ptrdiff_t
size_t
max_align_t
(C++11)
byte
(C++17)
nullptr_t
(C++11)
offsetof
NULL
Numeric limits
numeric_limits
C numeric limits interface
Runtime type information
type_info
type_index
(C++11)
bad_typeid
bad_cast
Type traits
Type categories
is_void
(C++11)
is_null_pointer
(C++14)
is_array
(C++11)
is_pointer
(C++11)
is_enum
(C++11)
is_union
(C++11)
is_class
(C++11)
is_function
(C++11)
is_object
(C++11)
is_scalar
(C++11)
is_compound
(C++11)
is_integral
(C++11)
is_floating_point
(C++11)
is_fundamental
(C++11)
is_arithmetic
(C++11)
is_reference
(C++11)
is_lvalue_reference
(C++11)
is_rvalue_reference
(C++11)
is_member_pointer
(C++11)
is_member_object_pointer
(C++11)
is_member_function_pointer
(C++11)
Type properties
is_const
(C++11)
is_volatile
(C++11)
is_empty
(C++11)
is_polymorphic
(C++11)
is_final
(C++14)
is_abstract
(C++11)
is_aggregate
(C++17)
is_trivial
(C++11)
is_trivially_copyable
(C++11)
is_standard_layout
(C++11)
is_literal_type
(C++11)(deprecated in C++17)
is_pod
(C++11)(deprecated in C++20)
is_signed
(C++11)
is_unsigned
(C++11)
has_unique_object_representations
(C++17)
Type trait constants
integral_constantbool_constanttrue_typefalse_type
(C++11)(C++17)(C++11)(C++11)
Metafunctions
conjunction
(C++17)
disjunction
(C++17)
negation
(C++17)
Endian
endian
(C++20)
Supported operations
is_constructibleis_trivially_constructibleis_nothrow_constructible
(C++11)(C++11)(C++11)
is_default_constructibleis_trivially_default_constructibleis_nothrow_default_constructible
(C++11)(C++11)(C++11)
is_copy_constructibleis_trivially_copy_constructibleis_nothrow_copy_constructible
(C++11)(C++11)(C++11)
is_move_constructibleis_trivially_move_constructibleis_nothrow_move_constructible
(C++11)(C++11)(C++11)
is_assignableis_trivially_assignableis_nothrow_assignable
(C++11)(C++11)(C++11)
is_copy_assignableis_trivially_copy_assignableis_nothrow_copy_assignable
(C++11)(C++11)(C++11)
is_move_assignableis_trivially_move_assignableis_nothrow_move_assignable
(C++11)(C++11)(C++11)
is_destructibleis_trivially_destructibleis_nothrow_destructible
(C++11)(C++11)(C++11)
has_virtual_destructor
(C++11)
is_swappable_withis_swappableis_nothrow_swappable_withis_nothrow_swappable
(C++17)(C++17)(C++17)(C++17)
Relationships and property queries
is_same
(C++11)
is_base_of
(C++11)
is_convertible
(C++11)
alignment_of
(C++11)
rank
(C++11)
extent
(C++11)
is_invocableis_invocable_ris_nothrow_invocableis_nothrow_invocable_r
(C++17)(C++17)(C++17)(C++17)
Type modifications
remove_cvremove_constremove_volatile
(C++11)(C++11)(C++11)
add_cvadd_constadd_volatile
(C++11)(C++11)(C++11)
make_signed
(C++11)
make_unsigned
(C++11)
remove_reference
(C++11)
add_lvalue_referenceadd_rvalue_reference
(C++11)(C++11)
remove_pointer
(C++11)
add_pointer
(C++11)
remove_extent
(C++11)
remove_all_extents
(C++11)
Type transformations
aligned_storage
(C++11)
aligned_union
(C++11)
decay
(C++11)
remove_cvref
(C++20)
enable_if
(C++11)
void_t
(C++17)
conditional
(C++11)
common_type
(C++11)
underlying_type
(C++11)
result_ofinvoke_result
(C++11)(deprecated in C++17)(C++17)
 
std::numeric_limits
Static constants
numeric_limits::is_specialized
numeric_limits::is_signed
numeric_limits::is_integer
numeric_limits::is_exact
numeric_limits::has_infinity
numeric_limits::has_quiet_NaN
numeric_limits::has_signaling_NaN
numeric_limits::has_denorm
numeric_limits::has_denorm_loss
numeric_limits::round_style
numeric_limits::is_iec559
numeric_limits::is_bounded
numeric_limits::is_modulo
numeric_limits::digits
numeric_limits::digits10
numeric_limits::max_digits10
(C++11)
numeric_limits::radix
numeric_limits::min_exponent
numeric_limits::min_exponent10
numeric_limits::max_exponent
numeric_limits::max_exponent10
numeric_limits::traps
numeric_limits::tinyness_before
Static member functions
numeric_limits::min
numeric_limits::lowest
(C++11)
numeric_limits::max
numeric_limits::epsilon
numeric_limits::round_error
numeric_limits::infinity
numeric_limits::quiet_NaN
numeric_limits::signaling_NaN
numeric_limits::denorm_min
Helper types
float_round_style
float_denorm_style
 
Defined in header <limits>
template< class T > class numeric_limits;

The numeric_limits class template provides a standardized way to query various properties of arithmetic types (e.g. the largest possible value for type int is std::numeric_limits<int>::max()).

This information is provided via specializations of the numeric_limits template. The standard library makes available specializations for all arithmetic types:

Defined in header <limits>
template<> class numeric_limits<bool>;

template<> class numeric_limits<char>;
template<> class numeric_limits<signed char>;
template<> class numeric_limits<unsigned char>;
template<> class numeric_limits<wchar_t>;
template<> class numeric_limits<char16_t>;   // C++11 feature
template<> class numeric_limits<char32_t>;   // C++11 feature
template<> class numeric_limits<short>;
template<> class numeric_limits<unsigned short>;
template<> class numeric_limits<int>;
template<> class numeric_limits<unsigned int>;
template<> class numeric_limits<long>;
template<> class numeric_limits<unsigned long>;
template<> class numeric_limits<long long>;
template<> class numeric_limits<unsigned long long>;
template<> class numeric_limits<float>;
template<> class numeric_limits<double>;

template<> class numeric_limits<long double>;

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

is_specialized
[static]
identifies types for which std::numeric_limits is specialized
(public static member constant)
is_signed
[static]
identifies signed types
(public static member constant)
is_integer
[static]
identifies integer types
(public static member constant)
is_exact
[static]
identifies exact types
(public static member constant)
has_infinity
[static]
identifies floating-point types that can represent the special value "positive infinity"
(public static member constant)
has_quiet_NaN
[static]
identifies floating-point types that can represent the special value "quiet not-a-number" (NaN)
(public static member constant)
has_signaling_NaN
[static]
identifies floating-point types that can represent the special value "signaling not-a-number" (NaN)
(public static member constant)
has_denorm
[static]
identifies the denormalization style used by the floating-point type
(public static member constant)
has_denorm_loss
[static]
identifies the floating-point types that detect loss of precision as denormalization loss rather than inexact result
(public static member constant)
round_style
[static]
identifies the rounding style used by the type
(public static member constant)
is_iec559
[static]
identifies the IEC 559/IEEE 754 floating-point types
(public static member constant)
is_bounded
[static]
identifies types that represent a finite set of values
(public static member constant)
is_modulo
[static]
identifies types that handle overflows with modulo arithmetic
(public static member constant)
digits
[static]
number of radix digits that can be represented without change
(public static member constant)
digits10
[static]
number of decimal digits that can be represented without change
(public static member constant)
max_digits10
[static] (C++11)
number of decimal digits necessary to differentiate all values of this type
(public static member constant)
radix
[static]
the radix or integer base used by the representation of the given type
(public static member constant)
min_exponent
[static]
one more than the smallest negative power of the radix that is a valid normalized floating-point value
(public static member constant)
min_exponent10
[static]
the smallest negative power of ten that is a valid normalized floating-point value
(public static member constant)
max_exponent
[static]
one more than the largest integer power of the radix that is a valid finite floating-point value
(public static member constant)
max_exponent10
[static]
the largest integer power of 10 that is a valid finite floating-point value
(public static member constant)
traps
[static]
identifies types which can cause arithmetic operations to trap
(public static member constant)
tinyness_before
[static]
identifies floating-point types that detect tinyness before rounding
(public static member constant)

Member functions

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

Helper classes

float_round_style
indicates floating-point rounding modes
(enum)
float_denorm_style
indicates floating-point denormalization modes
(enum)

Relationship with C library macro constants

Specialization Members
min() lowest()
(C++11)
max() epsilon() digits digits10 min_exponent min_exponent10 max_exponent max_exponent10 radix
numeric_limits< bool > 2
numeric_limits< char > CHAR_MIN CHAR_MIN CHAR_MAX 2
numeric_limits< signed char > SCHAR_MIN SCHAR_MIN SCHAR_MAX 2
numeric_limits< unsigned char > ​0​ ​0​ UCHAR_MAX 2
numeric_limits< wchar_t > WCHAR_MIN WCHAR_MIN WCHAR_MAX 2
numeric_limits< char16_t > ​0​ ​0​ UINT_LEAST16_MAX 2
numeric_limits< char32_t > ​0​ ​0​ UINT_LEAST32_MAX 2
numeric_limits< short > SHRT_MIN SHRT_MIN SHRT_MAX 2
numeric_limits< signed short >
numeric_limits< unsigned short > ​0​ ​0​ USHRT_MAX 2
numeric_limits< int > INT_MIN INT_MIN INT_MAX 2
numeric_limits< signed int >
numeric_limits< unsigned int > ​0​ ​0​ UINT_MAX 2
numeric_limits< long > LONG_MIN LONG_MIN LONG_MAX 2
numeric_limits< signed long >
numeric_limits< unsigned long > ​0​ ​0​ ULONG_MAX 2
numeric_limits< long long > LLONG_MIN LLONG_MIN LLONG_MAX 2
numeric_limits< signed long long >
numeric_limits< unsigned long long > ​0​ ​0​ ULLONG_MAX 2
numeric_limits< float > FLT_MIN -FLT_MAX FLT_MAX FLT_EPSILON FLT_MANT_DIG FLT_DIG FLT_MIN_EXP FLT_MIN_10_EXP FLT_MAX_EXP FLT_MAX_10_EXP FLT_RADIX
numeric_limits< double > DBL_MIN -DBL_MAX DBL_MAX DBL_EPSILON DBL_MANT_DIG DBL_DIG DBL_MIN_EXP DBL_MIN_10_EXP DBL_MAX_EXP DBL_MAX_10_EXP FLT_RADIX
numeric_limits< long double > LDBL_MIN -LDBL_MAX LDBL_MAX LDBL_EPSILON LDBL_MANT_DIG LDBL_DIG LDBL_MIN_EXP LDBL_MIN_10_EXP LDBL_MAX_EXP LDBL_MAX_10_EXP FLT_RADIX

Example

Run this code
#include <limits>
#include <iostream>
 
int main() 
{
    std::cout << "type\tlowest()\tmin()\t\tmax()\n\n";
 
    std::cout << "uchar\t"
              << +std::numeric_limits<unsigned char>::lowest() << '\t' << '\t'
              << +std::numeric_limits<unsigned char>::min() << '\t' << '\t'
              << +std::numeric_limits<unsigned char>::max() << '\n';
    std::cout << "int\t"
              << std::numeric_limits<int>::lowest() << '\t'
              << std::numeric_limits<int>::min() << '\t'
              << std::numeric_limits<int>::max() << '\n';
    std::cout << "float\t"
              << std::numeric_limits<float>::lowest() << '\t'
              << std::numeric_limits<float>::min() << '\t'
              << std::numeric_limits<float>::max() << '\n';
    std::cout << "double\t"
              << std::numeric_limits<double>::lowest() << '\t'
              << std::numeric_limits<double>::min() << '\t'
              << std::numeric_limits<double>::max() << '\n';
}

Possible output:

type	lowest()	min()		max()
 
uchar	0		0		255
int	-2147483648	-2147483648	2147483647
float	-3.40282e+38	1.17549e-38	3.40282e+38
double	-1.79769e+308	2.22507e-308	1.79769e+308

See also

  • Fixed width integer types
  • Arithmetic types
  • C++ type system overview
  • Type support (basic types, RTTI, type traits)
Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/types/numeric_limits&oldid=100926"
Navigation
  • Online version
  • Offline version retrieved 2018-04-14 22:05.
  • This page was last modified on 6 April 2018, at 07:26.
  • This page has been accessed 457,381 times.
mrJudge 31.05.2018 (F43DD)
Copyright © 2018 mrJudge. All rights reserved.

Under Construction

Stats Tab Content

Under Construction too