1 /* Test complex arithmetic with signed zeros.  Pure complex
2    multiplication with 1.0 + 0.0i.  */
3 /* { dg-do run } */
4 /* { dg-options "-std=gnu99" { target c } } */
5 
6 #include "complex-sign.h"
7 
8 #define CHECK_MUL_INT(TYPE, COPY, ZERO, ZEROI, ONE, S1, S2, SR, SI)	\
9   do {									\
10     _Complex TYPE a1, b1, c1;						\
11     volatile _Complex TYPE a2, b2, c2;					\
12     a1 = ENCODE(ZERO, ZEROI, S1, S2);					\
13     CHECK_RES (a1, COPY, S1, S2);					\
14     b1 = ONE + ZEROI;							\
15     c1 = a1 * b1;							\
16     CHECK_RES (c1, COPY, SR, SI);					\
17     c1 = a1 * (ONE + ZEROI);						\
18     CHECK_RES (c1, COPY, SR, SI);					\
19     a2 = ENCODE(ZERO, ZEROI, S1, S2);					\
20     CHECK_RES (a2, COPY, S1, S2);					\
21     b2 = ONE + ZEROI;							\
22     c2 = a2 * b2;							\
23     CHECK_RES (c2, COPY, SR, SI);					\
24     c2 = a2 * (ONE + ZEROI);						\
25     CHECK_RES (c2, COPY, SR, SI);					\
26   } while (0)
27 
28 #define CHECK_MUL(TYPE, COPY, ZERO, ZEROI, ONE)			\
29   do {								\
30     CHECK_MUL_INT (TYPE, COPY, ZERO, ZEROI, ONE, +, +, +, +);	\
31     CHECK_MUL_INT (TYPE, COPY, ZERO, ZEROI, ONE, +, -, +, +);	\
32     CHECK_MUL_INT (TYPE, COPY, ZERO, ZEROI, ONE, -, +, -, +);	\
33     CHECK_MUL_INT (TYPE, COPY, ZERO, ZEROI, ONE, -, -, +, -);	\
34   } while (0)
35 
36 void
check_mul_float(void)37 check_mul_float (void)
38 {
39   CHECK_MUL (float, __builtin_copysignf, 0.0f, 0.0if, 1.0f);
40 }
41 
42 void
check_mul_double(void)43 check_mul_double (void)
44 {
45   CHECK_MUL (double, __builtin_copysign, 0.0, 0.0i, 1.0);
46 }
47 
48 void
check_mul_long_double(void)49 check_mul_long_double (void)
50 {
51   CHECK_MUL (long double, __builtin_copysignl, 0.0l, 0.0il, 1.0l);
52 }
53 
54 int
main(void)55 main (void)
56 {
57   check_mul_float ();
58   check_mul_double ();
59   check_mul_long_double ();
60   exit (0);
61 }
62