1 // Copyright 2020 The Pigweed Authors
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
7 // https://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
18 #include "pw_polyfill/standard_library/namespace.h"
20 _PW_POLYFILL_BEGIN_NAMESPACE_STD
23 struct numeric_limits {
24 static constexpr bool is_specialized = false;
27 // Only a few of the numeric_limits methods are implemented.
28 #define _PW_LIMITS_SPECIALIZATION( \
29 type, val_signed, val_int, min_value, max_value) \
31 struct numeric_limits<type> { \
32 static constexpr bool is_specialized = true; \
34 static constexpr bool is_signed = (val_signed); \
35 static constexpr bool is_integer = (val_int); \
37 static constexpr type min() noexcept { return (min_value); } \
38 static constexpr type max() noexcept { return (max_value); } \
41 #define _PW_INTEGRAL_LIMIT(type, sname, uname) \
42 _PW_LIMITS_SPECIALIZATION( \
43 signed type, true, true, sname##_MIN, sname##_MAX); \
44 _PW_LIMITS_SPECIALIZATION(unsigned type, false, true, 0u, uname##_MAX)
46 _PW_LIMITS_SPECIALIZATION(bool, false, true, false, true);
47 _PW_LIMITS_SPECIALIZATION(char, char(-1) < char(0), true, CHAR_MIN, CHAR_MAX);
49 _PW_INTEGRAL_LIMIT(char, SCHAR, UCHAR);
50 _PW_INTEGRAL_LIMIT(short, SHRT, USHRT);
51 _PW_INTEGRAL_LIMIT(int, INT, UINT);
52 _PW_INTEGRAL_LIMIT(long, LONG, ULONG);
55 #define LLONG_MIN ((long long)(~0ull ^ (~0ull >> 1)))
56 #define LLONG_MAX ((long long)(~0ull >> 1))
58 #define ULLONG_MIN (0ull)
59 #define ULLONG_MAX (~0ull)
62 _PW_INTEGRAL_LIMIT(long long, LLONG, ULLONG);
64 #undef _PW_LIMITS_SPECIALIZATION
65 #undef _PW_INTEGRAL_LIMIT
67 _PW_POLYFILL_END_NAMESPACE_STD