* gcc.dg/c11-complex-1.c: New test.
[gcc.git] / gcc / testsuite / gcc.dg / c11-complex-1.c
1 /* Test complex divide does not have the bug identified in N1496. */
2 /* { dg-do run } */
3 /* { dg-options "-std=c11 -pedantic-errors" } */
4
5 extern void abort (void);
6 extern void exit (int);
7
8 #define CMPLX(x, y) __builtin_complex ((double) (x), (double) (y))
9 #define CMPLXF(x, y) __builtin_complex ((float) (x), (float) (y))
10 #define CMPLXL(x, y) __builtin_complex ((long double) (x), (long double) (y))
11 #define NAN __builtin_nanf ("")
12 #define isnan(x) __builtin_isnan (x)
13
14 volatile _Complex float num_f = CMPLXF (1, 1);
15 volatile _Complex float den_f = CMPLXF (0, NAN);
16 volatile _Complex float res_f, cres_f = CMPLXF (1, 1) / CMPLXF (0, NAN);
17
18 volatile _Complex double num_d = CMPLX (1, 1);
19 volatile _Complex double den_d = CMPLX (0, NAN);
20 volatile _Complex double res_d, cres_d = CMPLX (1, 1) / CMPLX (0, NAN);
21
22 volatile _Complex long double num_ld = CMPLXL (1, 1);
23 volatile _Complex long double den_ld = CMPLXL (0, NAN);
24 volatile _Complex long double res_ld, cres_ld = CMPLXL (1, 1) / CMPLXL (0, NAN);
25
26 int
27 main (void)
28 {
29 res_f = num_f / den_f;
30 if (!isnan (__real__ res_f) || !isnan (__imag__ res_f)
31 || !isnan (__real__ cres_f) || !isnan (__imag__ cres_f))
32 abort ();
33 res_d = num_d / den_d;
34 if (!isnan (__real__ res_d) || !isnan (__imag__ res_d)
35 || !isnan (__real__ cres_d) || !isnan (__imag__ cres_d))
36 abort ();
37 res_ld = num_ld / den_ld;
38 if (!isnan (__real__ res_ld) || !isnan (__imag__ res_ld)
39 || !isnan (__real__ cres_ld) || !isnan (__imag__ cres_ld))
40 abort ();
41 exit (0);
42 }