]> git.ipfire.org Git - thirdparty/glibc.git/blame - math/tst-CMPLX2.c
math: test-matherr and test-matherr-2 can be regular tests
[thirdparty/glibc.git] / math / tst-CMPLX2.c
CommitLineData
2b778ceb 1/* Copyright (C) 2012-2021 Free Software Foundation, Inc.
148cf100
MP
2 This file is part of the GNU C Library.
3 Contributed by Marek Polacek <polacek@redhat.com>, 2012.
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
59ba27a6 16 License along with the GNU C Library; if not, see
5a82c748 17 <https://www.gnu.org/licenses/>. */
148cf100
MP
18
19/* Adapted from gcc.dg/torture/builtin-complex-1.c test from GCC
20 testsuite written by Joseph S. Myers. */
21
22#include <complex.h>
23
24static int result;
25
26#define COMPARE_BODY(A, B, TYPE, COPYSIGN) \
27 do { \
28 TYPE s1 = COPYSIGN ((TYPE) 1.0, A); \
29 TYPE s2 = COPYSIGN ((TYPE) 1.0, B); \
30 if (s1 != s2) \
31 result |= 1; \
32 if ((__builtin_isnan (A) != 0) != (__builtin_isnan (B) != 0)) \
33 result |= 1; \
34 if ((A != B) != (__builtin_isnan (A) != 0)) \
35 result |= 1; \
36 } while (0)
37
38#ifdef CMPLX
39
40static void
41comparef (float a, float b)
42{
43 COMPARE_BODY (a, b, float, __builtin_copysignf);
44}
45
46static void
47compare (double a, double b)
48{
49 COMPARE_BODY (a, b, double, __builtin_copysign);
50}
51
52static void
53comparel (long double a, long double b)
54{
55 COMPARE_BODY (a, b, long double, __builtin_copysignl);
56}
57
58static void
59comparecf (_Complex float a, float r, float i)
60{
61 comparef (__real__ a, r);
62 comparef (__imag__ a, i);
63}
64
65static void
66comparec (_Complex double a, double r, double i)
67{
68 compare (__real__ a, r);
69 compare (__imag__ a, i);
70}
71
72static void
73comparecl (_Complex long double a, long double r, long double i)
74{
75 comparel (__real__ a, r);
76 comparel (__imag__ a, i);
77}
78
79#define VERIFY(A, B, TYPE, COMPARE, CL) \
80 do { \
81 TYPE a = A; \
82 TYPE b = B; \
83 _Complex TYPE cr = CL (a, b); \
84 static _Complex TYPE cs = CL (A, B); \
85 COMPARE (cr, A, B); \
86 COMPARE (cs, A, B); \
87 } while (0)
88
89#define ALL_CHECKS(PZ, NZ, NAN, INF, TYPE, COMPARE, CL) \
90 do { \
91 VERIFY (PZ, PZ, TYPE, COMPARE, CL); \
92 VERIFY (PZ, NZ, TYPE, COMPARE, CL); \
93 VERIFY (PZ, NAN, TYPE, COMPARE, CL); \
94 VERIFY (PZ, INF, TYPE, COMPARE, CL); \
95 VERIFY (NZ, PZ, TYPE, COMPARE, CL); \
96 VERIFY (NZ, NZ, TYPE, COMPARE, CL); \
97 VERIFY (NZ, NAN, TYPE, COMPARE, CL); \
98 VERIFY (NZ, INF, TYPE, COMPARE, CL); \
99 VERIFY (NAN, PZ, TYPE, COMPARE, CL); \
100 VERIFY (NAN, NZ, TYPE, COMPARE, CL); \
101 VERIFY (NAN, NAN, TYPE, COMPARE, CL); \
102 VERIFY (NAN, INF, TYPE, COMPARE, CL); \
103 VERIFY (INF, PZ, TYPE, COMPARE,CL); \
104 VERIFY (INF, NZ, TYPE, COMPARE, CL); \
105 VERIFY (INF, NAN, TYPE, COMPARE, CL); \
106 VERIFY (INF, INF, TYPE, COMPARE, CL); \
107 } while (0)
108
109static void
110check_float (void)
111{
112 ALL_CHECKS (0.0f, -0.0f, __builtin_nanf (""), __builtin_inff (),
113 float, comparecf, CMPLXF);
114}
115
116static void
117check_double (void)
118{
119 ALL_CHECKS (0.0, -0.0, __builtin_nan (""), __builtin_inf (),
120 double, comparec, CMPLX);
121}
122
148cf100
MP
123static void
124check_long_double (void)
125{
126 ALL_CHECKS (0.0l, -0.0l, __builtin_nanl (""), __builtin_infl (),
127 long double, comparecl, CMPLXL);
128}
148cf100
MP
129#endif
130
131static int
132do_test (void)
133{
134#ifdef CMPLX
135 check_float ();
136 check_double ();
148cf100 137 check_long_double ();
148cf100
MP
138#endif
139
140 return result;
141}
142
143#define TEST_FUNCTION do_test ()
144#include "../test-skeleton.c"