[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / libc / src / __support / CPP / limits.h
blobe163f00c73209115bd7cc473d822ff81d7291e0a
1 //===-- A self contained equivalent of std::limits --------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIBC_SRC___SUPPORT_CPP_LIMITS_H
10 #define LLVM_LIBC_SRC___SUPPORT_CPP_LIMITS_H
12 #include <limits.h>
14 namespace LIBC_NAMESPACE {
15 namespace cpp {
17 // Some older gcc distributions don't define these for 32 bit targets.
18 #ifndef LLONG_MAX
19 constexpr size_t LLONG_BIT_WIDTH = sizeof(long long) * 8;
20 constexpr long long LLONG_MAX = ~0LL ^ (1LL << (LLONG_BIT_WIDTH - 1));
21 constexpr long long LLONG_MIN = 1LL << (LLONG_BIT_WIDTH - 1);
22 constexpr unsigned long long ULLONG_MAX = ~0ULL;
23 #endif
25 template <class T> class numeric_limits {
26 public:
27 static constexpr T max();
28 static constexpr T min();
31 // TODO: Add numeric_limits specializations as needed for new types.
33 template <> class numeric_limits<int> {
34 public:
35 static constexpr int max() { return INT_MAX; }
36 static constexpr int min() { return INT_MIN; }
38 template <> class numeric_limits<unsigned int> {
39 public:
40 static constexpr unsigned int max() { return UINT_MAX; }
41 static constexpr unsigned int min() { return 0; }
43 template <> class numeric_limits<long> {
44 public:
45 static constexpr long max() { return LONG_MAX; }
46 static constexpr long min() { return LONG_MIN; }
48 template <> class numeric_limits<unsigned long> {
49 public:
50 static constexpr unsigned long max() { return ULONG_MAX; }
51 static constexpr unsigned long min() { return 0; }
53 template <> class numeric_limits<long long> {
54 public:
55 static constexpr long long max() { return LLONG_MAX; }
56 static constexpr long long min() { return LLONG_MIN; }
58 template <> class numeric_limits<unsigned long long> {
59 public:
60 static constexpr unsigned long long max() { return ULLONG_MAX; }
61 static constexpr unsigned long long min() { return 0; }
63 template <> class numeric_limits<short> {
64 public:
65 static constexpr short max() { return SHRT_MAX; }
66 static constexpr short min() { return SHRT_MIN; }
68 template <> class numeric_limits<unsigned short> {
69 public:
70 static constexpr unsigned short max() { return USHRT_MAX; }
71 static constexpr unsigned short min() { return 0; }
73 template <> class numeric_limits<char> {
74 public:
75 static constexpr char max() { return CHAR_MAX; }
76 static constexpr char min() { return CHAR_MIN; }
78 template <> class numeric_limits<signed char> {
79 public:
80 static constexpr signed char max() { return SCHAR_MAX; }
81 static constexpr signed char min() { return SCHAR_MIN; }
83 template <> class numeric_limits<unsigned char> {
84 public:
85 static constexpr unsigned char max() { return UCHAR_MAX; }
86 static constexpr unsigned char min() { return 0; }
88 #ifdef __SIZEOF_INT128__
89 // On platform where UInt128 resolves to __uint128_t, this specialization
90 // provides the limits of UInt128.
91 template <> class numeric_limits<__uint128_t> {
92 public:
93 static constexpr __uint128_t max() { return ~__uint128_t(0); }
94 static constexpr __uint128_t min() { return 0; }
96 #endif
98 } // namespace cpp
99 } // namespace LIBC_NAMESPACE
101 #endif // LLVM_LIBC_SRC___SUPPORT_CPP_LIMITS_H