]>
Commit | Line | Data |
---|---|---|
c85e54ac | 1 | /* Test for the C++ implementation of iseqsig. |
2b778ceb | 2 | Copyright (C) 2017-2021 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 | |
20 | #include <math.h> | |
21 | #include <stdio.h> | |
22 | ||
23 | #include <limits> | |
24 | ||
25 | /* There is no NaN for _Float128 in std::numeric_limits. | |
26 | Include ieee754_float128.h and use the bitfields in the union | |
27 | ieee854_float128.ieee_nan to build a NaN. */ | |
28 | #if __HAVE_DISTINCT_FLOAT128 | |
29 | # include <ieee754_float128.h> | |
30 | #endif | |
31 | ||
32 | #include <support/check.h> | |
33 | ||
34 | static void | |
35 | check (int actual, int expected, const char *actual_expr, int line) | |
36 | { | |
37 | if (actual != expected) | |
38 | { | |
39 | support_record_failure (); | |
40 | printf ("%s:%d: error: %s\n", __FILE__, line, actual_expr); | |
41 | printf ("%s:%d: expected: %d\n", __FILE__, line, expected); | |
42 | printf ("%s:%d: actual: %d\n", __FILE__, line, actual); | |
43 | } | |
44 | } | |
45 | ||
46 | #define CHECK(actual, expected) \ | |
47 | check ((actual), (expected), #actual, __LINE__) | |
48 | ||
49 | template <class T1, class T2> | |
50 | static void | |
51 | check_type () | |
52 | { | |
53 | T1 t1 = 0; | |
54 | T2 t2 = 0; | |
55 | CHECK (iseqsig (t1, t2), 1); | |
56 | ||
57 | t2 = 1; | |
58 | CHECK (iseqsig (t1, t2), 0); | |
59 | ||
60 | if (std::numeric_limits<T1>::has_quiet_NaN | |
61 | && std::numeric_limits<T2>::has_quiet_NaN) | |
62 | { | |
63 | CHECK (iseqsig (std::numeric_limits<T1>::quiet_NaN (), t2), 0); | |
64 | CHECK (iseqsig (t1, std::numeric_limits<T2>::quiet_NaN ()), 0); | |
65 | CHECK (iseqsig (std::numeric_limits<T1>::quiet_NaN (), | |
66 | std::numeric_limits<T2>::quiet_NaN ()), 0); | |
67 | } | |
68 | } | |
69 | ||
70 | #if __HAVE_DISTINCT_FLOAT128 | |
71 | static void | |
72 | check_float128 () | |
73 | { | |
74 | ieee854_float128 q1, q2, q3_nan; | |
75 | ||
76 | q1.d = 0; | |
77 | q2.d = 1; | |
78 | q3_nan.ieee_nan.negative = 0; | |
79 | q3_nan.ieee_nan.exponent = 0x7FFF; | |
80 | q3_nan.ieee_nan.quiet_nan = 1; | |
81 | q3_nan.ieee_nan.mantissa0 = 0x0000; | |
82 | q3_nan.ieee_nan.mantissa1 = 0x00000000; | |
83 | q3_nan.ieee_nan.mantissa2 = 0x00000000; | |
84 | q3_nan.ieee_nan.mantissa3 = 0x00000000; | |
85 | ||
86 | CHECK (iseqsig (q1.d, q1.d), 1); | |
87 | CHECK (iseqsig (q1.d, q2.d), 0); | |
88 | CHECK (iseqsig (q1.d, q3_nan.d), 0); | |
89 | CHECK (iseqsig (q3_nan.d, q3_nan.d), 0); | |
90 | } | |
91 | #endif | |
92 | ||
93 | static int | |
94 | do_test (void) | |
95 | { | |
96 | check_type<float, float> (); | |
97 | check_type<float, double> (); | |
98 | check_type<float, long double> (); | |
99 | check_type<double, float> (); | |
100 | check_type<double, double> (); | |
101 | check_type<double, long double> (); | |
102 | check_type<long double, float> (); | |
103 | check_type<long double, double> (); | |
104 | check_type<long double, long double> (); | |
105 | #if __HAVE_DISTINCT_FLOAT128 | |
106 | check_float128 (); | |
107 | #endif | |
108 | return 0; | |
109 | } | |
110 | ||
111 | #include <support/test-driver.c> |