2008-03-21 Janne Blomqvist <jb@gcc.gnu.org>
[official-gcc.git] / gcc / testsuite / gcc.dg / builtins-54.c
blob2713a3b1d57565248d64908baa92f765452abd7a
1 /* { dg-do link } */
2 /* { dg-options "-O2 -ffast-math" } */
4 double fabs(double);
5 float fabsf(float);
6 long double fabsl(long double);
7 double cabs(__complex__ double);
8 float cabsf(__complex__ float);
9 long double cabsl(__complex__ long double);
11 void link_error (void);
13 void test(__complex__ double x, double a, double b)
15 if (cabs(x) != cabs(-x))
16 link_error();
18 if (cabs(x) != cabs(~x))
19 link_error();
21 if (fabs(a) * __builtin_sqrt(2) != cabs (a+a*1i))
22 link_error();
24 if (fabs(a) * __builtin_sqrt(2) != cabs (a*1i+a))
25 link_error();
27 if (fabs(a) * __builtin_sqrt(2) != cabs (-a+a*-1i))
28 link_error();
30 if (fabs(a) * __builtin_sqrt(2) != cabs (-a+-a*1i))
31 link_error();
33 if (fabs(a) * __builtin_sqrt(2) != cabs (-a-a*1i))
34 link_error();
36 if (fabs(a) * __builtin_sqrt(2) != cabs (a*-1i-a))
37 link_error();
39 if (fabs(a) * __builtin_sqrt(2) != cabs (-a*1i-a))
40 link_error();
42 if (fabs(a) * __builtin_sqrt(2) != cabs (a*-1i+-a))
43 link_error();
45 if (fabs(a) * __builtin_sqrt(2) != cabs (-a*1i+-a))
46 link_error();
48 if (fabs(a*b) * __builtin_sqrt(2) != cabs (a*b-(-b*a*1i)))
49 link_error();
51 if (fabs(a*b) * __builtin_sqrt(2) != cabs (a*b*1i-a*-b))
52 link_error();
55 void testf(__complex__ float x, float a, float b)
57 if (cabsf(x) != cabsf(-x))
58 link_error();
60 if (cabsf(x) != cabsf(~x))
61 link_error();
63 if (fabsf(a) * __builtin_sqrtf(2) != cabsf (a+a*1i))
64 link_error();
66 if (fabsf(a) * __builtin_sqrtf(2) != cabsf (a*1i+a))
67 link_error();
69 if (fabsf(a) * __builtin_sqrtf(2) != cabsf (-a+a*-1i))
70 link_error();
72 if (fabsf(a) * __builtin_sqrtf(2) != cabsf (-a+-a*1i))
73 link_error();
75 if (fabsf(a) * __builtin_sqrtf(2) != cabsf (-a-a*1i))
76 link_error();
78 if (fabsf(a) * __builtin_sqrtf(2) != cabsf (a*-1i-a))
79 link_error();
81 if (fabsf(a) * __builtin_sqrtf(2) != cabsf (-a*1i-a))
82 link_error();
84 if (fabsf(a) * __builtin_sqrtf(2) != cabsf (a*-1i+-a))
85 link_error();
87 if (fabsf(a) * __builtin_sqrtf(2) != cabsf (-a*1i+-a))
88 link_error();
90 if (fabsf(a*b) * __builtin_sqrtf(2) != cabsf (a*b-(-b*a*1i)))
91 link_error();
93 if (fabsf(a*b) * __builtin_sqrtf(2) != cabsf (a*b*1i-a*-b))
94 link_error();
97 void testl(__complex__ long double x, long double a, long double b)
99 if (cabsl(x) != cabsl(-x))
100 link_error();
102 if (cabsl(x) != cabsl(~x))
103 link_error();
105 if (fabsl(a) * __builtin_sqrtl(2) != cabsl (a+a*1i))
106 link_error();
108 if (fabsl(a) * __builtin_sqrtl(2) != cabsl (a*1i+a))
109 link_error();
111 if (fabsl(a) * __builtin_sqrtl(2) != cabsl (-a+a*-1i))
112 link_error();
114 if (fabsl(a) * __builtin_sqrtl(2) != cabsl (-a+-a*1i))
115 link_error();
117 if (fabsl(a) * __builtin_sqrtl(2) != cabsl (-a-a*1i))
118 link_error();
120 if (fabsl(a) * __builtin_sqrtl(2) != cabsl (a*-1i-a))
121 link_error();
123 if (fabsl(a) * __builtin_sqrtl(2) != cabsl (-a*1i-a))
124 link_error();
126 if (fabsl(a) * __builtin_sqrtl(2) != cabsl (a*-1i+-a))
127 link_error();
129 if (fabsl(a) * __builtin_sqrtl(2) != cabsl (-a*1i+-a))
130 link_error();
132 if (fabsl(a*b) * __builtin_sqrtl(2) != cabsl (a*b-(-b*a*1i)))
133 link_error();
135 if (fabsl(a*b) * __builtin_sqrtl(2) != cabsl (a*b*1i-a*-b))
136 link_error();
139 int main()
141 test(0, 0, 0);
142 testf(0, 0, 0);
143 testl(0, 0, 0);
144 return 0;