2014-08-04 Ed Schonberg <schonberg@adacore.com>
[official-gcc.git] / gcc / testsuite / gcc.dg / torture / builtin-complex-1.c
blob0d26c9cc707dc3a9acfcfee3963986372e893a75
1 /* Test __builtin_complex semantics. */
2 /* { dg-do run } */
3 /* { dg-options "-std=c11 -pedantic-errors" } */
4 /* { dg-add-options ieee } */
6 extern void exit (int);
7 extern void abort (void);
9 #define COMPARE_BODY(A, B, TYPE, COPYSIGN) \
10 do { \
11 TYPE s1 = COPYSIGN ((TYPE) 1.0, A); \
12 TYPE s2 = COPYSIGN ((TYPE) 1.0, B); \
13 if (s1 != s2) \
14 abort (); \
15 if ((__builtin_isnan (A) != 0) != (__builtin_isnan (B) != 0)) \
16 abort (); \
17 if ((A != B) != (__builtin_isnan (A) != 0)) \
18 abort (); \
19 } while (0)
21 #ifndef __SPU__
22 void
23 comparef (float a, float b)
25 COMPARE_BODY (a, b, float, __builtin_copysignf);
27 #endif
29 void
30 compare (double a, double b)
32 COMPARE_BODY (a, b, double, __builtin_copysign);
35 void
36 comparel (long double a, long double b)
38 COMPARE_BODY (a, b, long double, __builtin_copysignl);
41 #ifndef __SPU__
42 void
43 comparecf (_Complex float a, float r, float i)
45 comparef (__real__ a, r);
46 comparef (__imag__ a, i);
48 #endif
50 void
51 comparec (_Complex double a, double r, double i)
53 compare (__real__ a, r);
54 compare (__imag__ a, i);
57 void
58 comparecl (_Complex long double a, long double r, long double i)
60 comparel (__real__ a, r);
61 comparel (__imag__ a, i);
64 #define VERIFY(A, B, TYPE, COMPARE) \
65 do { \
66 TYPE a = A; \
67 TYPE b = B; \
68 _Complex TYPE cr = __builtin_complex (a, b); \
69 static _Complex TYPE cs = __builtin_complex (A, B); \
70 COMPARE (cr, A, B); \
71 COMPARE (cs, A, B); \
72 } while (0)
74 #define ALL_CHECKS(PZ, NZ, NAN, INF, TYPE, COMPARE) \
75 do { \
76 VERIFY (PZ, PZ, TYPE, COMPARE); \
77 VERIFY (PZ, NZ, TYPE, COMPARE); \
78 VERIFY (PZ, NAN, TYPE, COMPARE); \
79 VERIFY (PZ, INF, TYPE, COMPARE); \
80 VERIFY (NZ, PZ, TYPE, COMPARE); \
81 VERIFY (NZ, NZ, TYPE, COMPARE); \
82 VERIFY (NZ, NAN, TYPE, COMPARE); \
83 VERIFY (NZ, INF, TYPE, COMPARE); \
84 VERIFY (NAN, PZ, TYPE, COMPARE); \
85 VERIFY (NAN, NZ, TYPE, COMPARE); \
86 VERIFY (NAN, NAN, TYPE, COMPARE); \
87 VERIFY (NAN, INF, TYPE, COMPARE); \
88 VERIFY (INF, PZ, TYPE, COMPARE); \
89 VERIFY (INF, NZ, TYPE, COMPARE); \
90 VERIFY (INF, NAN, TYPE, COMPARE); \
91 VERIFY (INF, INF, TYPE, COMPARE); \
92 } while (0)
94 void
95 check_float (void)
97 #ifndef __SPU__
98 ALL_CHECKS (0.0f, -0.0f, __builtin_nanf(""), __builtin_inff(),
99 float, comparecf);
100 #endif
103 void
104 check_double (void)
106 ALL_CHECKS (0.0, -0.0, __builtin_nan(""), __builtin_inf(),
107 double, comparec);
110 void
111 check_long_double (void)
113 ALL_CHECKS (0.0l, -0.0l, __builtin_nanl(""), __builtin_infl(),
114 long double, comparecl);
118 main (void)
120 check_float ();
121 check_double ();
122 check_long_double ();
123 exit (0);