1 | //===----------------------------------------------------------------------===// |
---|---|
2 | // DuckDB |
3 | // |
4 | // duckdb/common/limits.hpp |
5 | // |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #pragma once |
10 | |
11 | #include "duckdb/common/types.hpp" |
12 | |
13 | // Undef annoying windows macro |
14 | #undef max |
15 | |
16 | #include <limits> |
17 | |
18 | namespace duckdb { |
19 | |
20 | template <class T> |
21 | struct NumericLimits { |
22 | static constexpr T Minimum() { |
23 | return std::numeric_limits<T>::lowest(); |
24 | }; |
25 | static constexpr T Maximum() { |
26 | return std::numeric_limits<T>::max(); |
27 | }; |
28 | DUCKDB_API static bool IsSigned(); |
29 | DUCKDB_API static idx_t Digits(); |
30 | }; |
31 | |
32 | template <> |
33 | struct NumericLimits<int8_t> { |
34 | static constexpr int8_t Minimum() { |
35 | return std::numeric_limits<int8_t>::lowest(); |
36 | }; |
37 | static constexpr int8_t Maximum() { |
38 | return std::numeric_limits<int8_t>::max(); |
39 | }; |
40 | static bool IsSigned() { |
41 | return true; |
42 | } |
43 | static idx_t Digits() { |
44 | return 3; |
45 | } |
46 | }; |
47 | template <> |
48 | struct NumericLimits<int16_t> { |
49 | static constexpr int16_t Minimum() { |
50 | return std::numeric_limits<int16_t>::lowest(); |
51 | }; |
52 | static constexpr int16_t Maximum() { |
53 | return std::numeric_limits<int16_t>::max(); |
54 | }; |
55 | static bool IsSigned() { |
56 | return true; |
57 | } |
58 | static idx_t Digits() { |
59 | return 5; |
60 | } |
61 | }; |
62 | template <> |
63 | struct NumericLimits<int32_t> { |
64 | static constexpr int32_t Minimum() { |
65 | return std::numeric_limits<int32_t>::lowest(); |
66 | }; |
67 | static constexpr int32_t Maximum() { |
68 | return std::numeric_limits<int32_t>::max(); |
69 | }; |
70 | static bool IsSigned() { |
71 | return true; |
72 | } |
73 | static idx_t Digits() { |
74 | return 10; |
75 | } |
76 | }; |
77 | |
78 | template <> |
79 | struct NumericLimits<int64_t> { |
80 | static constexpr int64_t Minimum() { |
81 | return std::numeric_limits<int64_t>::lowest(); |
82 | }; |
83 | static constexpr int64_t Maximum() { |
84 | return std::numeric_limits<int64_t>::max(); |
85 | }; |
86 | static bool IsSigned() { |
87 | return true; |
88 | } |
89 | static idx_t Digits() { |
90 | return 19; |
91 | } |
92 | }; |
93 | template <> |
94 | struct NumericLimits<hugeint_t> { |
95 | static constexpr hugeint_t Minimum() { |
96 | return {std::numeric_limits<int64_t>::lowest(), 1}; |
97 | }; |
98 | static constexpr hugeint_t Maximum() { |
99 | return {std::numeric_limits<int64_t>::max(), std::numeric_limits<uint64_t>::max()}; |
100 | }; |
101 | static bool IsSigned() { |
102 | return true; |
103 | } |
104 | static idx_t Digits() { |
105 | return 39; |
106 | } |
107 | }; |
108 | |
109 | template <> |
110 | struct NumericLimits<uint8_t> { |
111 | static constexpr uint8_t Minimum() { |
112 | return std::numeric_limits<uint8_t>::lowest(); |
113 | }; |
114 | static constexpr uint8_t Maximum() { |
115 | return std::numeric_limits<uint8_t>::max(); |
116 | }; |
117 | static bool IsSigned() { |
118 | return false; |
119 | } |
120 | static idx_t Digits() { |
121 | return 3; |
122 | } |
123 | }; |
124 | |
125 | template <> |
126 | struct NumericLimits<uint16_t> { |
127 | static constexpr uint16_t Minimum() { |
128 | return std::numeric_limits<uint16_t>::lowest(); |
129 | }; |
130 | static constexpr uint16_t Maximum() { |
131 | return std::numeric_limits<uint16_t>::max(); |
132 | }; |
133 | static bool IsSigned() { |
134 | return false; |
135 | } |
136 | static idx_t Digits() { |
137 | return 5; |
138 | } |
139 | }; |
140 | template <> |
141 | struct NumericLimits<uint32_t> { |
142 | static constexpr uint32_t Minimum() { |
143 | return std::numeric_limits<uint32_t>::lowest(); |
144 | }; |
145 | static constexpr uint32_t Maximum() { |
146 | return std::numeric_limits<uint32_t>::max(); |
147 | }; |
148 | static bool IsSigned() { |
149 | return false; |
150 | } |
151 | static idx_t Digits() { |
152 | return 10; |
153 | } |
154 | }; |
155 | template <> |
156 | struct NumericLimits<uint64_t> { |
157 | static constexpr uint64_t Minimum() { |
158 | return std::numeric_limits<uint64_t>::lowest(); |
159 | }; |
160 | static constexpr uint64_t Maximum() { |
161 | return std::numeric_limits<uint64_t>::max(); |
162 | }; |
163 | static bool IsSigned() { |
164 | return false; |
165 | } |
166 | static idx_t Digits() { |
167 | return 20; |
168 | } |
169 | }; |
170 | template <> |
171 | struct NumericLimits<float> { |
172 | static constexpr float Minimum() { |
173 | return std::numeric_limits<float>::lowest(); |
174 | }; |
175 | static constexpr float Maximum() { |
176 | return std::numeric_limits<float>::max(); |
177 | }; |
178 | static bool IsSigned() { |
179 | return true; |
180 | } |
181 | static idx_t Digits() { |
182 | return 127; |
183 | } |
184 | }; |
185 | template <> |
186 | struct NumericLimits<double> { |
187 | static constexpr double Minimum() { |
188 | return std::numeric_limits<double>::lowest(); |
189 | }; |
190 | static constexpr double Maximum() { |
191 | return std::numeric_limits<double>::max(); |
192 | }; |
193 | static bool IsSigned() { |
194 | return true; |
195 | } |
196 | static idx_t Digits() { |
197 | return 250; |
198 | } |
199 | }; |
200 | |
201 | } // namespace duckdb |
202 |