]>
Commit | Line | Data |
---|---|---|
c85e54ac | 1 | /* Test for the C++ implementation of iseqsig. |
6d7e8eda | 2 | Copyright (C) 2017-2023 Free Software Foundation, Inc. |
c85e54ac GG |
3 | This file is part of the GNU C Library. |
4 | ||
5 | The GNU C Library is free software; you can redistribute it and/or | |
6 | modify it under the terms of the GNU Lesser General Public | |
7 | License as published by the Free Software Foundation; either | |
8 | version 2.1 of the License, or (at your option) any later version. | |
9 | ||
10 | The GNU C Library is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | Lesser General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU Lesser General Public | |
16 | License along with the GNU C Library; if not, see | |
5a82c748 | 17 | <https://www.gnu.org/licenses/>. */ |
c85e54ac GG |
18 | |
19 | #define _GNU_SOURCE 1 | |
ba70f695 | 20 | #include <float.h> |
c85e54ac GG |
21 | #include <math.h> |
22 | #include <stdio.h> | |
23 | ||
24 | #include <limits> | |
25 | ||
26 | /* There is no NaN for _Float128 in std::numeric_limits. | |
27 | Include ieee754_float128.h and use the bitfields in the union | |
28 | ieee854_float128.ieee_nan to build a NaN. */ | |
29 | #if __HAVE_DISTINCT_FLOAT128 | |
30 | # include <ieee754_float128.h> | |
31 | #endif | |
32 | ||
33 | #include <support/check.h> | |
34 | ||
35 | static void | |
36 | check (int actual, int expected, const char *actual_expr, int line) | |
37 | { | |
38 | if (actual != expected) | |
39 | { | |
40 | support_record_failure (); | |
41 | printf ("%s:%d: error: %s\n", __FILE__, line, actual_expr); | |
42 | printf ("%s:%d: expected: %d\n", __FILE__, line, expected); | |
43 | printf ("%s:%d: actual: %d\n", __FILE__, line, actual); | |
44 | } | |
45 | } | |
46 | ||
47 | #define CHECK(actual, expected) \ | |
48 | check ((actual), (expected), #actual, __LINE__) | |
49 | ||
50 | template <class T1, class T2> | |
51 | static void | |
52 | check_type () | |
53 | { | |
54 | T1 t1 = 0; | |
55 | T2 t2 = 0; | |
56 | CHECK (iseqsig (t1, t2), 1); | |
57 | ||
58 | t2 = 1; | |
59 | CHECK (iseqsig (t1, t2), 0); | |
60 | ||
61 | if (std::numeric_limits<T1>::has_quiet_NaN | |
62 | && std::numeric_limits<T2>::has_quiet_NaN) | |
63 | { | |
64 | CHECK (iseqsig (std::numeric_limits<T1>::quiet_NaN (), t2), 0); | |
65 | CHECK (iseqsig (t1, std::numeric_limits<T2>::quiet_NaN ()), 0); | |
66 | CHECK (iseqsig (std::numeric_limits<T1>::quiet_NaN (), | |
67 | std::numeric_limits<T2>::quiet_NaN ()), 0); | |
68 | } | |
69 | } | |
70 | ||
ba70f695 JM |
71 | /* Run minimal tests of iseqsig for a pair of types, without relying |
72 | on C++ library support or knowledge of the representation. */ | |
73 | template <class T1, class T2> | |
74 | static void | |
75 | check_type_minimal () | |
76 | { | |
77 | T1 t1 = 0; | |
78 | T2 t2 = 0; | |
79 | CHECK (iseqsig (t1, t2), 1); | |
80 | ||
81 | t2 = 1; | |
82 | CHECK (iseqsig (t1, t2), 0); | |
83 | } | |
84 | ||
c85e54ac GG |
85 | #if __HAVE_DISTINCT_FLOAT128 |
86 | static void | |
87 | check_float128 () | |
88 | { | |
89 | ieee854_float128 q1, q2, q3_nan; | |
90 | ||
91 | q1.d = 0; | |
92 | q2.d = 1; | |
93 | q3_nan.ieee_nan.negative = 0; | |
94 | q3_nan.ieee_nan.exponent = 0x7FFF; | |
95 | q3_nan.ieee_nan.quiet_nan = 1; | |
96 | q3_nan.ieee_nan.mantissa0 = 0x0000; | |
97 | q3_nan.ieee_nan.mantissa1 = 0x00000000; | |
98 | q3_nan.ieee_nan.mantissa2 = 0x00000000; | |
99 | q3_nan.ieee_nan.mantissa3 = 0x00000000; | |
100 | ||
101 | CHECK (iseqsig (q1.d, q1.d), 1); | |
102 | CHECK (iseqsig (q1.d, q2.d), 0); | |
103 | CHECK (iseqsig (q1.d, q3_nan.d), 0); | |
104 | CHECK (iseqsig (q3_nan.d, q3_nan.d), 0); | |
105 | } | |
106 | #endif | |
107 | ||
108 | static int | |
109 | do_test (void) | |
110 | { | |
111 | check_type<float, float> (); | |
112 | check_type<float, double> (); | |
113 | check_type<float, long double> (); | |
114 | check_type<double, float> (); | |
115 | check_type<double, double> (); | |
116 | check_type<double, long double> (); | |
117 | check_type<long double, float> (); | |
118 | check_type<long double, double> (); | |
119 | check_type<long double, long double> (); | |
120 | #if __HAVE_DISTINCT_FLOAT128 | |
121 | check_float128 (); | |
122 | #endif | |
ba70f695 JM |
123 | |
124 | #if __HAVE_FLOAT16 | |
125 | check_type_minimal<float, _Float16> (); | |
126 | #endif | |
127 | #if __HAVE_FLOAT32 | |
128 | check_type_minimal<float, _Float32> (); | |
129 | #endif | |
130 | #if __HAVE_FLOAT64 | |
131 | check_type_minimal<float, _Float64> (); | |
132 | #endif | |
133 | #if __HAVE_FLOAT128 | |
134 | check_type_minimal<float, _Float128> (); | |
135 | #endif | |
136 | #if __HAVE_FLOAT32X | |
137 | check_type_minimal<float, _Float32x> (); | |
138 | #endif | |
139 | #if __HAVE_FLOAT64X | |
140 | check_type_minimal<float, _Float64x> (); | |
141 | #endif | |
142 | #if __HAVE_FLOAT128X | |
143 | check_type_minimal<float, _Float128x> (); | |
144 | #endif | |
145 | #if __HAVE_FLOAT16 | |
146 | check_type_minimal<double, _Float16> (); | |
147 | #endif | |
148 | #if __HAVE_FLOAT32 | |
149 | check_type_minimal<double, _Float32> (); | |
150 | #endif | |
151 | #if __HAVE_FLOAT64 | |
152 | check_type_minimal<double, _Float64> (); | |
153 | #endif | |
154 | #if __HAVE_FLOAT128 | |
155 | check_type_minimal<double, _Float128> (); | |
156 | #endif | |
157 | #if __HAVE_FLOAT32X | |
158 | check_type_minimal<double, _Float32x> (); | |
159 | #endif | |
160 | #if __HAVE_FLOAT64X | |
161 | check_type_minimal<double, _Float64x> (); | |
162 | #endif | |
163 | #if __HAVE_FLOAT128X | |
164 | check_type_minimal<double, _Float128x> (); | |
165 | #endif | |
166 | #if __HAVE_FLOAT16 | |
167 | check_type_minimal<long double, _Float16> (); | |
168 | #endif | |
169 | #if __HAVE_FLOAT32 | |
170 | check_type_minimal<long double, _Float32> (); | |
171 | #endif | |
172 | #if __HAVE_FLOAT64 | |
173 | check_type_minimal<long double, _Float64> (); | |
174 | #endif | |
175 | #if __HAVE_FLOAT128 && LDBL_MANT_DIG != 106 | |
176 | check_type_minimal<long double, _Float128> (); | |
177 | #endif | |
178 | #if __HAVE_FLOAT32X | |
179 | check_type_minimal<long double, _Float32x> (); | |
180 | #endif | |
181 | #if __HAVE_FLOAT64X && LDBL_MANT_DIG != 106 | |
182 | check_type_minimal<long double, _Float64x> (); | |
183 | #endif | |
184 | #if __HAVE_FLOAT128X && LDBL_MANT_DIG != 106 | |
185 | check_type_minimal<long double, _Float128x> (); | |
186 | #endif | |
187 | #if __HAVE_FLOAT16 | |
188 | check_type_minimal<_Float16, float> (); | |
189 | #endif | |
190 | #if __HAVE_FLOAT16 | |
191 | check_type_minimal<_Float16, double> (); | |
192 | #endif | |
193 | #if __HAVE_FLOAT16 | |
194 | check_type_minimal<_Float16, long double> (); | |
195 | #endif | |
196 | #if __HAVE_FLOAT16 | |
197 | check_type_minimal<_Float16, _Float16> (); | |
198 | #endif | |
199 | #if __HAVE_FLOAT16 && __HAVE_FLOAT32 | |
200 | check_type_minimal<_Float16, _Float32> (); | |
201 | #endif | |
202 | #if __HAVE_FLOAT16 && __HAVE_FLOAT64 | |
203 | check_type_minimal<_Float16, _Float64> (); | |
204 | #endif | |
205 | #if __HAVE_FLOAT16 && __HAVE_FLOAT128 | |
206 | check_type_minimal<_Float16, _Float128> (); | |
207 | #endif | |
208 | #if __HAVE_FLOAT16 && __HAVE_FLOAT32X | |
209 | check_type_minimal<_Float16, _Float32x> (); | |
210 | #endif | |
211 | #if __HAVE_FLOAT16 && __HAVE_FLOAT64X | |
212 | check_type_minimal<_Float16, _Float64x> (); | |
213 | #endif | |
214 | #if __HAVE_FLOAT16 && __HAVE_FLOAT128X | |
215 | check_type_minimal<_Float16, _Float128x> (); | |
216 | #endif | |
217 | #if __HAVE_FLOAT32 | |
218 | check_type_minimal<_Float32, float> (); | |
219 | #endif | |
220 | #if __HAVE_FLOAT32 | |
221 | check_type_minimal<_Float32, double> (); | |
222 | #endif | |
223 | #if __HAVE_FLOAT32 | |
224 | check_type_minimal<_Float32, long double> (); | |
225 | #endif | |
226 | #if __HAVE_FLOAT32 && __HAVE_FLOAT16 | |
227 | check_type_minimal<_Float32, _Float16> (); | |
228 | #endif | |
229 | #if __HAVE_FLOAT32 | |
230 | check_type_minimal<_Float32, _Float32> (); | |
231 | #endif | |
232 | #if __HAVE_FLOAT32 && __HAVE_FLOAT64 | |
233 | check_type_minimal<_Float32, _Float64> (); | |
234 | #endif | |
235 | #if __HAVE_FLOAT32 && __HAVE_FLOAT128 | |
236 | check_type_minimal<_Float32, _Float128> (); | |
237 | #endif | |
238 | #if __HAVE_FLOAT32 && __HAVE_FLOAT32X | |
239 | check_type_minimal<_Float32, _Float32x> (); | |
240 | #endif | |
241 | #if __HAVE_FLOAT32 && __HAVE_FLOAT64X | |
242 | check_type_minimal<_Float32, _Float64x> (); | |
243 | #endif | |
244 | #if __HAVE_FLOAT32 && __HAVE_FLOAT128X | |
245 | check_type_minimal<_Float32, _Float128x> (); | |
246 | #endif | |
247 | #if __HAVE_FLOAT64 | |
248 | check_type_minimal<_Float64, float> (); | |
249 | #endif | |
250 | #if __HAVE_FLOAT64 | |
251 | check_type_minimal<_Float64, double> (); | |
252 | #endif | |
253 | #if __HAVE_FLOAT64 | |
254 | check_type_minimal<_Float64, long double> (); | |
255 | #endif | |
256 | #if __HAVE_FLOAT64 && __HAVE_FLOAT16 | |
257 | check_type_minimal<_Float64, _Float16> (); | |
258 | #endif | |
259 | #if __HAVE_FLOAT64 && __HAVE_FLOAT32 | |
260 | check_type_minimal<_Float64, _Float32> (); | |
261 | #endif | |
262 | #if __HAVE_FLOAT64 | |
263 | check_type_minimal<_Float64, _Float64> (); | |
264 | #endif | |
265 | #if __HAVE_FLOAT64 && __HAVE_FLOAT128 | |
266 | check_type_minimal<_Float64, _Float128> (); | |
267 | #endif | |
268 | #if __HAVE_FLOAT64 && __HAVE_FLOAT32X | |
269 | check_type_minimal<_Float64, _Float32x> (); | |
270 | #endif | |
271 | #if __HAVE_FLOAT64 && __HAVE_FLOAT64X | |
272 | check_type_minimal<_Float64, _Float64x> (); | |
273 | #endif | |
274 | #if __HAVE_FLOAT64 && __HAVE_FLOAT128X | |
275 | check_type_minimal<_Float64, _Float128x> (); | |
276 | #endif | |
277 | #if __HAVE_FLOAT128 | |
278 | check_type_minimal<_Float128, float> (); | |
279 | #endif | |
280 | #if __HAVE_FLOAT128 | |
281 | check_type_minimal<_Float128, double> (); | |
282 | #endif | |
283 | #if __HAVE_FLOAT128 && LDBL_MANT_DIG != 106 | |
284 | check_type_minimal<_Float128, long double> (); | |
285 | #endif | |
286 | #if __HAVE_FLOAT128 && __HAVE_FLOAT16 | |
287 | check_type_minimal<_Float128, _Float16> (); | |
288 | #endif | |
289 | #if __HAVE_FLOAT128 && __HAVE_FLOAT32 | |
290 | check_type_minimal<_Float128, _Float32> (); | |
291 | #endif | |
292 | #if __HAVE_FLOAT128 && __HAVE_FLOAT64 | |
293 | check_type_minimal<_Float128, _Float64> (); | |
294 | #endif | |
295 | #if __HAVE_FLOAT128 | |
296 | check_type_minimal<_Float128, _Float128> (); | |
297 | #endif | |
298 | #if __HAVE_FLOAT128 && __HAVE_FLOAT32X | |
299 | check_type_minimal<_Float128, _Float32x> (); | |
300 | #endif | |
301 | #if __HAVE_FLOAT128 && __HAVE_FLOAT64X | |
302 | check_type_minimal<_Float128, _Float64x> (); | |
303 | #endif | |
304 | #if __HAVE_FLOAT128 && __HAVE_FLOAT128X | |
305 | check_type_minimal<_Float128, _Float128x> (); | |
306 | #endif | |
307 | #if __HAVE_FLOAT32X | |
308 | check_type_minimal<_Float32x, float> (); | |
309 | #endif | |
310 | #if __HAVE_FLOAT32X | |
311 | check_type_minimal<_Float32x, double> (); | |
312 | #endif | |
313 | #if __HAVE_FLOAT32X | |
314 | check_type_minimal<_Float32x, long double> (); | |
315 | #endif | |
316 | #if __HAVE_FLOAT32X && __HAVE_FLOAT16 | |
317 | check_type_minimal<_Float32x, _Float16> (); | |
318 | #endif | |
319 | #if __HAVE_FLOAT32X && __HAVE_FLOAT32 | |
320 | check_type_minimal<_Float32x, _Float32> (); | |
321 | #endif | |
322 | #if __HAVE_FLOAT32X && __HAVE_FLOAT64 | |
323 | check_type_minimal<_Float32x, _Float64> (); | |
324 | #endif | |
325 | #if __HAVE_FLOAT32X && __HAVE_FLOAT128 | |
326 | check_type_minimal<_Float32x, _Float128> (); | |
327 | #endif | |
328 | #if __HAVE_FLOAT32X | |
329 | check_type_minimal<_Float32x, _Float32x> (); | |
330 | #endif | |
331 | #if __HAVE_FLOAT32X && __HAVE_FLOAT64X | |
332 | check_type_minimal<_Float32x, _Float64x> (); | |
333 | #endif | |
334 | #if __HAVE_FLOAT32X && __HAVE_FLOAT128X | |
335 | check_type_minimal<_Float32x, _Float128x> (); | |
336 | #endif | |
337 | #if __HAVE_FLOAT64X | |
338 | check_type_minimal<_Float64x, float> (); | |
339 | #endif | |
340 | #if __HAVE_FLOAT64X | |
341 | check_type_minimal<_Float64x, double> (); | |
342 | #endif | |
343 | #if __HAVE_FLOAT64X && LDBL_MANT_DIG != 106 | |
344 | check_type_minimal<_Float64x, long double> (); | |
345 | #endif | |
346 | #if __HAVE_FLOAT64X && __HAVE_FLOAT16 | |
347 | check_type_minimal<_Float64x, _Float16> (); | |
348 | #endif | |
349 | #if __HAVE_FLOAT64X && __HAVE_FLOAT32 | |
350 | check_type_minimal<_Float64x, _Float32> (); | |
351 | #endif | |
352 | #if __HAVE_FLOAT64X && __HAVE_FLOAT64 | |
353 | check_type_minimal<_Float64x, _Float64> (); | |
354 | #endif | |
355 | #if __HAVE_FLOAT64X && __HAVE_FLOAT128 | |
356 | check_type_minimal<_Float64x, _Float128> (); | |
357 | #endif | |
358 | #if __HAVE_FLOAT64X && __HAVE_FLOAT32X | |
359 | check_type_minimal<_Float64x, _Float32x> (); | |
360 | #endif | |
361 | #if __HAVE_FLOAT64X | |
362 | check_type_minimal<_Float64x, _Float64x> (); | |
363 | #endif | |
364 | #if __HAVE_FLOAT64X && __HAVE_FLOAT128X | |
365 | check_type_minimal<_Float64x, _Float128x> (); | |
366 | #endif | |
367 | #if __HAVE_FLOAT128X | |
368 | check_type_minimal<_Float128x, float> (); | |
369 | #endif | |
370 | #if __HAVE_FLOAT128X | |
371 | check_type_minimal<_Float128x, double> (); | |
372 | #endif | |
373 | #if __HAVE_FLOAT128X && LDBL_MANT_DIG != 106 | |
374 | check_type_minimal<_Float128x, long double> (); | |
375 | #endif | |
376 | #if __HAVE_FLOAT128X && __HAVE_FLOAT16 | |
377 | check_type_minimal<_Float128x, _Float16> (); | |
378 | #endif | |
379 | #if __HAVE_FLOAT128X && __HAVE_FLOAT32 | |
380 | check_type_minimal<_Float128x, _Float32> (); | |
381 | #endif | |
382 | #if __HAVE_FLOAT128X && __HAVE_FLOAT64 | |
383 | check_type_minimal<_Float128x, _Float64> (); | |
384 | #endif | |
385 | #if __HAVE_FLOAT128X && __HAVE_FLOAT128 | |
386 | check_type_minimal<_Float128x, _Float128> (); | |
387 | #endif | |
388 | #if __HAVE_FLOAT128X && __HAVE_FLOAT32X | |
389 | check_type_minimal<_Float128x, _Float32x> (); | |
390 | #endif | |
391 | #if __HAVE_FLOAT128X && __HAVE_FLOAT64X | |
392 | check_type_minimal<_Float128x, _Float64x> (); | |
393 | #endif | |
394 | #if __HAVE_FLOAT128X | |
395 | check_type_minimal<_Float128x, _Float128x> (); | |
396 | #endif | |
397 | ||
c85e54ac GG |
398 | return 0; |
399 | } | |
400 | ||
401 | #include <support/test-driver.c> |