1//===----------------------------------------------------------------------===//
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//===----------------------------------------------------------------------===//
8
9// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
10
11#include <limits>
12
13#include "test_macros.h"
14
15/*
16<limits>:
17 numeric_limits
18 is_specialized
19 digits
20 digits10
21 max_digits10
22 is_signed
23 is_integer
24 is_exact
25 radix
26 min_exponent
27 min_exponent10
28 max_exponent
29 max_exponent10
30 has_infinity
31 has_quiet_NaN
32 has_signaling_NaN
33 has_denorm
34 has_denorm_loss
35 is_iec559
36 is_bounded
37 is_modulo
38 traps
39 tinyness_before
40 round_style
41*/
42
43template <class T>
44void test(const T &) {}
45
46#define TEST_NUMERIC_LIMITS(type) \
47 test(std::numeric_limits<type>::is_specialized); \
48 test(std::numeric_limits<type>::digits); \
49 test(std::numeric_limits<type>::digits10); \
50 test(std::numeric_limits<type>::max_digits10); \
51 test(std::numeric_limits<type>::is_signed); \
52 test(std::numeric_limits<type>::is_integer); \
53 test(std::numeric_limits<type>::is_exact); \
54 test(std::numeric_limits<type>::radix); \
55 test(std::numeric_limits<type>::min_exponent); \
56 test(std::numeric_limits<type>::min_exponent10); \
57 test(std::numeric_limits<type>::max_exponent); \
58 test(std::numeric_limits<type>::max_exponent10); \
59 test(std::numeric_limits<type>::has_infinity); \
60 test(std::numeric_limits<type>::has_quiet_NaN); \
61 test(std::numeric_limits<type>::has_signaling_NaN); \
62 test(std::numeric_limits<type>::has_denorm); \
63 test(std::numeric_limits<type>::has_denorm_loss); \
64 test(std::numeric_limits<type>::is_iec559); \
65 test(std::numeric_limits<type>::is_bounded); \
66 test(std::numeric_limits<type>::is_modulo); \
67 test(std::numeric_limits<type>::traps); \
68 test(std::numeric_limits<type>::tinyness_before); \
69 test(std::numeric_limits<type>::round_style);
70
71struct other {};
72
73int main(int, char**)
74{
75 // bool
76 TEST_NUMERIC_LIMITS(bool)
77 TEST_NUMERIC_LIMITS(const bool)
78 TEST_NUMERIC_LIMITS(volatile bool)
79 TEST_NUMERIC_LIMITS(const volatile bool)
80
81 // char
82 TEST_NUMERIC_LIMITS(char)
83 TEST_NUMERIC_LIMITS(const char)
84 TEST_NUMERIC_LIMITS(volatile char)
85 TEST_NUMERIC_LIMITS(const volatile char)
86
87 // signed char
88 TEST_NUMERIC_LIMITS(signed char)
89 TEST_NUMERIC_LIMITS(const signed char)
90 TEST_NUMERIC_LIMITS(volatile signed char)
91 TEST_NUMERIC_LIMITS(const volatile signed char)
92
93 // unsigned char
94 TEST_NUMERIC_LIMITS(unsigned char)
95 TEST_NUMERIC_LIMITS(const unsigned char)
96 TEST_NUMERIC_LIMITS(volatile unsigned char)
97 TEST_NUMERIC_LIMITS(const volatile unsigned char)
98
99 // wchar_t
100 TEST_NUMERIC_LIMITS(wchar_t)
101 TEST_NUMERIC_LIMITS(const wchar_t)
102 TEST_NUMERIC_LIMITS(volatile wchar_t)
103 TEST_NUMERIC_LIMITS(const volatile wchar_t)
104
105#if TEST_STD_VER > 17 && defined(__cpp_char8_t)
106 // char8_t
107 TEST_NUMERIC_LIMITS(char8_t)
108 TEST_NUMERIC_LIMITS(const char8_t)
109 TEST_NUMERIC_LIMITS(volatile char8_t)
110 TEST_NUMERIC_LIMITS(const volatile char8_t)
111#endif
112
113 // char16_t
114 TEST_NUMERIC_LIMITS(char16_t)
115 TEST_NUMERIC_LIMITS(const char16_t)
116 TEST_NUMERIC_LIMITS(volatile char16_t)
117 TEST_NUMERIC_LIMITS(const volatile char16_t)
118
119 // char32_t
120 TEST_NUMERIC_LIMITS(char32_t)
121 TEST_NUMERIC_LIMITS(const char32_t)
122 TEST_NUMERIC_LIMITS(volatile char32_t)
123 TEST_NUMERIC_LIMITS(const volatile char32_t)
124
125 // short
126 TEST_NUMERIC_LIMITS(short)
127 TEST_NUMERIC_LIMITS(const short)
128 TEST_NUMERIC_LIMITS(volatile short)
129 TEST_NUMERIC_LIMITS(const volatile short)
130
131 // int
132 TEST_NUMERIC_LIMITS(int)
133 TEST_NUMERIC_LIMITS(const int)
134 TEST_NUMERIC_LIMITS(volatile int)
135 TEST_NUMERIC_LIMITS(const volatile int)
136
137 // long
138 TEST_NUMERIC_LIMITS(long)
139 TEST_NUMERIC_LIMITS(const long)
140 TEST_NUMERIC_LIMITS(volatile long)
141 TEST_NUMERIC_LIMITS(const volatile long)
142
143#ifndef TEST_HAS_NO_INT128
144 TEST_NUMERIC_LIMITS(__int128_t)
145 TEST_NUMERIC_LIMITS(const __int128_t)
146 TEST_NUMERIC_LIMITS(volatile __int128_t)
147 TEST_NUMERIC_LIMITS(const volatile __int128_t)
148#endif
149
150 // long long
151 TEST_NUMERIC_LIMITS(long long)
152 TEST_NUMERIC_LIMITS(const long long)
153 TEST_NUMERIC_LIMITS(volatile long long)
154 TEST_NUMERIC_LIMITS(const volatile long long)
155
156 // unsigned short
157 TEST_NUMERIC_LIMITS(unsigned short)
158 TEST_NUMERIC_LIMITS(const unsigned short)
159 TEST_NUMERIC_LIMITS(volatile unsigned short)
160 TEST_NUMERIC_LIMITS(const volatile unsigned short)
161
162 // unsigned int
163 TEST_NUMERIC_LIMITS(unsigned int)
164 TEST_NUMERIC_LIMITS(const unsigned int)
165 TEST_NUMERIC_LIMITS(volatile unsigned int)
166 TEST_NUMERIC_LIMITS(const volatile unsigned int)
167
168 // unsigned long
169 TEST_NUMERIC_LIMITS(unsigned long)
170 TEST_NUMERIC_LIMITS(const unsigned long)
171 TEST_NUMERIC_LIMITS(volatile unsigned long)
172 TEST_NUMERIC_LIMITS(const volatile unsigned long)
173
174 // unsigned long long
175 TEST_NUMERIC_LIMITS(unsigned long long)
176 TEST_NUMERIC_LIMITS(const unsigned long long)
177 TEST_NUMERIC_LIMITS(volatile unsigned long long)
178 TEST_NUMERIC_LIMITS(const volatile unsigned long long)
179
180#ifndef TEST_HAS_NO_INT128
181 TEST_NUMERIC_LIMITS(__uint128_t)
182 TEST_NUMERIC_LIMITS(const __uint128_t)
183 TEST_NUMERIC_LIMITS(volatile __uint128_t)
184 TEST_NUMERIC_LIMITS(const volatile __uint128_t)
185#endif
186
187 // float
188 TEST_NUMERIC_LIMITS(float)
189 TEST_NUMERIC_LIMITS(const float)
190 TEST_NUMERIC_LIMITS(volatile float)
191 TEST_NUMERIC_LIMITS(const volatile float)
192
193 // double
194 TEST_NUMERIC_LIMITS(double)
195 TEST_NUMERIC_LIMITS(const double)
196 TEST_NUMERIC_LIMITS(volatile double)
197 TEST_NUMERIC_LIMITS(const volatile double)
198
199 // long double
200 TEST_NUMERIC_LIMITS(long double)
201 TEST_NUMERIC_LIMITS(const long double)
202 TEST_NUMERIC_LIMITS(volatile long double)
203 TEST_NUMERIC_LIMITS(const volatile long double)
204
205 // other
206 TEST_NUMERIC_LIMITS(other)
207 TEST_NUMERIC_LIMITS(const other)
208 TEST_NUMERIC_LIMITS(volatile other)
209 TEST_NUMERIC_LIMITS(const volatile other)
210
211 return 0;
212}
213

source code of libcxx/test/std/language.support/support.limits/limits/numeric.limits.members/const_data_members.pass.cpp