Debian Codegraph @

gcc/testsuite/gcc.dg/torture/builtin-complex-1.c

raw
1 /* Test __builtin_complex semantics. */
2 /* { dg-do run } */
3 /* { dg-options "-std=c11 -pedantic-errors" } */
4 /* { dg-require-effective-target inf } */
5 /* { dg-add-options ieee } */
6 /* { dg-skip-if "double support is incomplete" { "avr-*-*" } } */
7
8 extern void exit (int);
9 extern void abort (void);
10
11 #define COMPARE_BODY(A, B, TYPE, COPYSIGN) \
12 do { \
13 TYPE s1 = COPYSIGN ((TYPE) 1.0, A); \
14 TYPE s2 = COPYSIGN ((TYPE) 1.0, B); \
15 if (s1 != s2) \
16 abort (); \
17 if ((__builtin_isnan (A) != 0) != (__builtin_isnan (B) != 0)) \
18 abort (); \
19 if ((A != B) != (__builtin_isnan (A) != 0)) \
20 abort (); \
21 } while (0)
22
23 void
24 comparef (float a, float b)
25 {
26 COMPARE_BODY (a, b, float, __builtin_copysignf);
27 }
28
29 void
30 compare (double a, double b)
31 {
32 COMPARE_BODY (a, b, double, __builtin_copysign);
33 }
34
35 void
36 comparel (long double a, long double b)
37 {
38 COMPARE_BODY (a, b, long double, __builtin_copysignl);
39 }
40
41 void
42 comparecf (_Complex float a, float r, float i)
43 {
44 comparef (__real__ a, r);
45 comparef (__imag__ a, i);
46 }
47
48 void
49 comparec (_Complex double a, double r, double i)
50 {
51 compare (__real__ a, r);
52 compare (__imag__ a, i);
53 }
54
55 void
56 comparecl (_Complex long double a, long double r, long double i)
57 {
58 comparel (__real__ a, r);
59 comparel (__imag__ a, i);
60 }
61
62 #define VERIFY(A, B, TYPE, COMPARE) \
63 do { \
64 TYPE a = A; \
65 TYPE b = B; \
66 _Complex TYPE cr = __builtin_complex (a, b); \
67 static _Complex TYPE cs = __builtin_complex (A, B); \
68 COMPARE (cr, A, B); \
69 COMPARE (cs, A, B); \
70 } while (0)
71
72 #define ALL_CHECKS(PZ, NZ, NAN, INF, TYPE, COMPARE) \
73 do { \
74 VERIFY (PZ, PZ, TYPE, COMPARE); \
75 VERIFY (PZ, NZ, TYPE, COMPARE); \
76 VERIFY (PZ, NAN, TYPE, COMPARE); \
77 VERIFY (PZ, INF, TYPE, COMPARE); \
78 VERIFY (NZ, PZ, TYPE, COMPARE); \
79 VERIFY (NZ, NZ, TYPE, COMPARE); \
80 VERIFY (NZ, NAN, TYPE, COMPARE); \
81 VERIFY (NZ, INF, TYPE, COMPARE); \
82 VERIFY (NAN, PZ, TYPE, COMPARE); \
83 VERIFY (NAN, NZ, TYPE, COMPARE); \
84 VERIFY (NAN, NAN, TYPE, COMPARE); \
85 VERIFY (NAN, INF, TYPE, COMPARE); \
86 VERIFY (INF, PZ, TYPE, COMPARE); \
87 VERIFY (INF, NZ, TYPE, COMPARE); \
88 VERIFY (INF, NAN, TYPE, COMPARE); \
89 VERIFY (INF, INF, TYPE, COMPARE); \
90 } while (0)
91
92 void
93 check_float (void)
94 {
95 ALL_CHECKS (0.0f, -0.0f, __builtin_nanf(""), __builtin_inff(),
96 float, comparecf);
97 }
98
99 void
100 check_double (void)
101 {
102 ALL_CHECKS (0.0, -0.0, __builtin_nan(""), __builtin_inf(),
103 double, comparec);
104 }
105
106 void
107 check_long_double (void)
108 {
109 ALL_CHECKS (0.0l, -0.0l, __builtin_nanl(""), __builtin_infl(),
110 long double, comparecl);
111 }
112
113 int
114 main (void)
115 {
116 check_float ();
117 check_double ();
118 check_long_double ();
119 exit (0);
120 }