[libc][NFC] Move aligned access implementations to separate header
[llvm-project.git] / libc / src / __support / CPP / limits.h
blob225bf6ee7770d45f327f8a0bf05ab063a3026e16
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 __llvm_libc {
15 namespace cpp {
17 template <class T> class numeric_limits {
18 public:
19 static constexpr T max();
20 static constexpr T min();
23 // TODO: Add numeric_limits specializations as needed for new types.
25 template <> class numeric_limits<int> {
26 public:
27 static constexpr int max() { return INT_MAX; }
28 static constexpr int min() { return INT_MIN; }
30 template <> class numeric_limits<unsigned int> {
31 public:
32 static constexpr unsigned int max() { return UINT_MAX; }
33 static constexpr unsigned int min() { return 0; }
35 template <> class numeric_limits<long> {
36 public:
37 static constexpr long max() { return LONG_MAX; }
38 static constexpr long min() { return LONG_MIN; }
40 template <> class numeric_limits<unsigned long> {
41 public:
42 static constexpr unsigned long max() { return ULONG_MAX; }
43 static constexpr unsigned long min() { return 0; }
45 template <> class numeric_limits<long long> {
46 public:
47 static constexpr long long max() { return LLONG_MAX; }
48 static constexpr long long min() { return LLONG_MIN; }
50 template <> class numeric_limits<unsigned long long> {
51 public:
52 static constexpr unsigned long long max() { return ULLONG_MAX; }
53 static constexpr unsigned long long min() { return 0; }
55 template <> class numeric_limits<short> {
56 public:
57 static constexpr short max() { return SHRT_MAX; }
58 static constexpr short min() { return SHRT_MIN; }
60 template <> class numeric_limits<unsigned short> {
61 public:
62 static constexpr unsigned short max() { return USHRT_MAX; }
63 static constexpr unsigned short min() { return 0; }
65 template <> class numeric_limits<char> {
66 public:
67 static constexpr char max() { return CHAR_MAX; }
68 static constexpr char min() { return CHAR_MIN; }
70 template <> class numeric_limits<unsigned char> {
71 public:
72 static constexpr unsigned char max() { return UCHAR_MAX; }
73 static constexpr unsigned char min() { return 0; }
75 #ifdef __SIZEOF_INT128__
76 // On platform where UInt128 resolves to __uint128_t, this specialization
77 // provides the limits of UInt128.
78 template <> class numeric_limits<__uint128_t> {
79 public:
80 static constexpr __uint128_t max() { return ~__uint128_t(0); }
81 static constexpr __uint128_t min() { return 0; }
83 #endif
85 } // namespace cpp
86 } // namespace __llvm_libc
88 #endif // LLVM_LIBC_SRC_SUPPORT_CPP_LIMITS_H