Merge to HEAD at tree-cleanup-merge-20041024 .
[official-gcc.git] / gcc / testsuite / gcc.dg / builtins-18.c
bloba47de8b609eedee82beac0c9dc0047e6f83d3c4a
1 /* Copyright (C) 2003 Free Software Foundation.
3 Check that built-in cabs, cabsf and cabsl functions don't
4 break anything and produces the expected results.
6 Written by Roger Sayle, 1st June 2003. */
8 /* { dg-do link } */
9 /* { dg-options "-O2 -ffast-math" } */
11 #include "builtins-config.h"
13 extern void link_error(void);
15 extern float cabsf (float _Complex);
16 extern double cabs (double _Complex);
17 extern long double cabsl (long double _Complex);
19 int
20 main (void)
22 /* For each type, test both runtime and compile time (constant folding)
23 optimization. */
24 float _Complex fc = 3.0F + 4.0iF;
25 double _Complex dc = 3.0 + 4.0i;
26 long double _Complex ldc = 3.0L + 4.0iL;
28 #ifdef HAVE_C99_RUNTIME
29 /* Test floats. */
30 if (cabsf (fc) != 5.0F)
31 link_error ();
32 if (__builtin_cabsf (fc) != 5.0F)
33 link_error ();
34 if (cabsf (3.0F + 4.0iF) != 5.0F)
35 link_failure ();
36 if (__builtin_cabsf (3.0F + 4.0iF) != 5.0F)
37 link_failure ();
38 #endif
40 /* Test doubles. */
41 if (cabs (dc) != 5.0)
42 link_error ();
43 if (__builtin_cabs (dc) != 5.0)
44 link_error ();
45 if (cabs (3.0 + 4.0i) != 5.0)
46 link_failure ();
47 if (__builtin_cabs (3.0 + 4.0i) != 5.0)
48 link_failure ();
50 #ifdef HAVE_C99_RUNTIME
51 /* Test long doubles. */
52 if (cabsl (ldc) != 5.0L)
53 link_error ();
54 if (__builtin_cabsl (ldc) != 5.0L)
55 link_error ();
56 if (cabsl (3.0L + 4.0iL) != 5.0L)
57 link_failure ();
58 if (__builtin_cabsl (3.0L + 4.0iL) != 5.0L)
59 link_failure ();
60 #endif
62 return 0;