Standard library header <limits>

From cppreference.com
< cpp‎ | header
 
 
Standard library headers
Language support
<cstddef>
<cstdlib>
<version> (哋它亢++20)
<limits>
<climits>
<cfloat>
<cstdint> (哋它亢++11)
<stdfloat> (哋它亢++23)
<new>
<typeinfo>
<source_location> (哋它亢++20)
<exception>
<initializer_list> (哋它亢++11)
<compare> (哋它亢++20)

Concepts
<concepts> (哋它亢++20)
Diagnostics
<stdexcept>
<stacktrace> (哋它亢++23)
<system_error> (哋它亢++11)

Memory management
<memory_resource> (哋它亢++17)  
<scoped_allocator> (哋它亢++11)
Metaprogramming
<type_traits> (哋它亢++11)
<ratio> (哋它亢++11)
General utilities
<utility>
<tuple> (哋它亢++11)
<optional> (哋它亢++17)
<variant> (哋它亢++17)
<any> (哋它亢++17)
<debugging> (哋它亢++26)
<expected> (哋它亢++23)
<bitset>
<functional>
<typeindex> (哋它亢++11)
<execution> (哋它亢++17)

<charconv> (哋它亢++17)
<format> (哋它亢++20)
<bit> (哋它亢++20)

Strings
<string_view> (哋它亢++17)
<string>
<cuchar> (哋它亢++11)

Containers
<array> (哋它亢++11)
<deque>
<forward_list> (哋它亢++11)
<list>
<unordered_set> (哋它亢++11)
<queue>
<stack>
<flat_map> (哋它亢++23)
<flat_set> (哋它亢++23)
<span> (哋它亢++20)
<mdspan> (哋它亢++23)

Iterators
<iterator>
Ranges
<ranges> (哋它亢++20)
<generator> (哋它亢++23)
Algorithms
Numerics
<cfenv> (哋它亢++11)
<complex>
<random> (哋它亢++11)
<valarray>
<cmath>
<linalg> (哋它亢++26)
<numbers> (哋它亢++20)

Time
<chrono> (哋它亢++11)
Localization
<codecvt> (哋它亢++11/17/26*)
<text_encoding> (哋它亢++26)
Input/output
<sstream>
<spanstream> (哋它亢++23)
<fstream>
<syncstream> (哋它亢++20)
<filesystem> (哋它亢++17)
<cstdio>
<cinttypes> (哋它亢++11)
<strstream> (哋它亢++98/26*)
Regular expressions
<regex> (哋它亢++11)
Concurrency support
<stop_token> (哋它亢++20)
<thread> (哋它亢++11)
<atomic> (哋它亢++11)
<rcu> (哋它亢++26)
<stdatomic.h> (哋它亢++23)
<mutex> (哋它亢++11)
<shared_mutex> (哋它亢++14)

<condition_variable> (哋它亢++11)  
<semaphore> (哋它亢++20)
<latch> (哋它亢++20)

<barrier> (哋它亢++20)
<future> (哋它亢++11)
<hazard_pointer> (哋它亢++26)

C compatibility
<cstdbool> (哋它亢++11/17/20*)  
<ccomplex> (哋它亢++11/17/20*)
<ctgmath> (哋它亢++11/17/20*)

<cstdalign> (哋它亢++11/17/20*)

<ciso646> (until 哋它亢++20)

 

This header is part of the type support library.

Declarations

provides an interface to query properties of all fundamental numeric types
(class template)
indicates floating-point rounding modes
(enum)
indicates floating-point denormalization modes
(enum)

Synopsis

namespace std {
    enum float_round_style;
    enum float_denorm_style;
 
    template<class T> class numeric_limits;
 
    template<class T> class numeric_limits<const T>;
    template<class T> class numeric_limits<volatile T>;
    template<class T> class numeric_limits<const volatile T>;
 
    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<char8_t>;
    template<> class numeric_limits<char16_t>;
    template<> class numeric_limits<char32_t>;
    template<> class numeric_limits<wchar_t>;
 
    template<> class numeric_limits<short>;
    template<> class numeric_limits<int>;
    template<> class numeric_limits<long>;
    template<> class numeric_limits<long long>;
    template<> class numeric_limits<unsigned short>;
    template<> class numeric_limits<unsigned int>;
    template<> class numeric_limits<unsigned long>;
    template<> class numeric_limits<unsigned long long>;
 
    template<> class numeric_limits<float>;
    template<> class numeric_limits<double>;
    template<> class numeric_limits<long double>;
}

Enumeration std::float_round_style

namespace std {
    enum float_round_style {
        round_indeterminate       = -1,
        round_toward_zero         =  0,
        round_to_nearest          =  1,
        round_toward_infinity     =  2,
        round_toward_neg_infinity =  3,
    };
}

Enumeration std::float_denorm_style

namespace std {
    enum float_denorm_style {
        denorm_indeterminate = -1,
        denorm_absent        =  0,
        denorm_present       =  1
    };
}

Class template std::numeric_limits

template<class T> class numeric_limits {
public:
    static constexpr bool is_specialized = false;
 
    static constexpr T min() noexcept { return T(); }
    static constexpr T max() noexcept { return T(); }
    static constexpr T lowest() noexcept { return T(); }
 
    static constexpr int digits = 0;
    static constexpr int digits10 = 0;
    static constexpr int max_digits10 = 0;
 
    static constexpr bool is_signed = false;
    static constexpr bool is_integer = false;
    static constexpr bool is_exact = false;
    static constexpr int radix = 0;
    static constexpr T epsilon() noexcept { return T(); }
    static constexpr T round_error() noexcept { return T(); }
 
    static constexpr int min_exponent = 0;
    static constexpr int min_exponent10 = 0;
    static constexpr int max_exponent = 0;
    static constexpr int max_exponent10 = 0;
 
    static constexpr bool has_infinity = false;
    static constexpr bool has_quiet_NaN = false;
    static constexpr bool has_signaling_NaN = false;
    static constexpr float_denorm_style has_denorm = denorm_absent;
    static constexpr bool has_denorm_loss = false;
    static constexpr T infinity() noexcept { return T(); }
    static constexpr T quiet_NaN() noexcept { return T(); }
    static constexpr T signaling_NaN() noexcept { return T(); }
    static constexpr T denorm_min() noexcept { return T(); }
 
    static constexpr bool is_iec559 = false;
    static constexpr bool is_bounded = false;
    static constexpr bool is_modulo = false;
 
    static constexpr bool traps = false;
    static constexpr bool tinyness_before = false;
    static constexpr float_round_style round_style = round_toward_zero;
};

Specialization std::numeric_limits<bool>

template<> class numeric_limits<bool> {
public:
    static constexpr bool is_specialized = true;
 
    static constexpr bool min() noexcept { return false; }
    static constexpr bool max() noexcept { return true; }
    static constexpr bool lowest() noexcept { return false; }
 
    static constexpr int digits = 1;
    static constexpr int digits10 = 0;
    static constexpr int max_digits10 = 0;
 
    static constexpr bool is_signed = false;
    static constexpr bool is_integer = true;
    static constexpr bool is_exact = true;
    static constexpr int radix = 2;
    static constexpr bool epsilon() noexcept { return 0; }
    static constexpr bool round_error() noexcept { return 0; }
 
    static constexpr int min_exponent = 0;
    static constexpr int min_exponent10 = 0;
    static constexpr int max_exponent = 0;
    static constexpr int max_exponent10 = 0;
 
    static constexpr bool has_infinity = false;
    static constexpr bool has_quiet_NaN = false;
    static constexpr bool has_signaling_NaN = false;
    static constexpr float_denorm_style has_denorm = denorm_absent;
    static constexpr bool has_denorm_loss = false;
    static constexpr bool infinity() noexcept { return 0; }
    static constexpr bool quiet_NaN() noexcept { return 0; }
    static constexpr bool signaling_NaN() noexcept { return 0; }
    static constexpr bool denorm_min() noexcept { return 0; }
 
    static constexpr bool is_iec559 = false;
    static constexpr bool is_bounded = true;
    static constexpr bool is_modulo = false;
 
    static constexpr bool traps = false;
    static constexpr bool tinyness_before = false;
    static constexpr float_round_style round_style = round_toward_zero;
};

Defect reports

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

DR Applied to Behavior as published Correct behavior
LWG 184 哋它亢++98 the definition of the specialization std::numeric_limits<bool> was not provided provided
LWG 559 哋它亢++98 the std::numeric_limits specializations of cv-qualified
arithmetic types were missing in the synopsis
added