* Merge from mainline
[official-gcc.git] / gcc / testsuite / gcc.dg / builtins-18.c
blobf4f64c1acb3c9b47d957f8720ed757e4ea94a4a2
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" } */
10 /* { dg-options "-O2 -ffast-math -mmacosx-version-min=10.3" { target powerpc-*-darwin* } } */
11 /* { dg-options "-O2 -ffast-math -std=c99" { target *-*-solaris2* } } */
13 #include "builtins-config.h"
15 extern void link_error(void);
17 extern float cabsf (float _Complex);
18 extern double cabs (double _Complex);
19 extern long double cabsl (long double _Complex);
21 int
22 main (void)
24 /* For each type, test both runtime and compile time (constant folding)
25 optimization. */
26 float _Complex fc = 3.0F + 4.0iF;
27 double _Complex dc = 3.0 + 4.0i;
28 long double _Complex ldc = 3.0L + 4.0iL;
30 #ifdef HAVE_C99_RUNTIME
31 /* Test floats. */
32 if (cabsf (fc) != 5.0F)
33 link_error ();
34 if (__builtin_cabsf (fc) != 5.0F)
35 link_error ();
36 if (cabsf (3.0F + 4.0iF) != 5.0F)
37 link_error ();
38 if (__builtin_cabsf (3.0F + 4.0iF) != 5.0F)
39 link_error ();
40 #endif
42 /* Test doubles. */
43 if (cabs (dc) != 5.0)
44 link_error ();
45 if (__builtin_cabs (dc) != 5.0)
46 link_error ();
47 if (cabs (3.0 + 4.0i) != 5.0)
48 link_error ();
49 if (__builtin_cabs (3.0 + 4.0i) != 5.0)
50 link_error ();
52 #ifdef HAVE_C99_RUNTIME
53 /* Test long doubles. */
54 if (cabsl (ldc) != 5.0L)
55 link_error ();
56 if (__builtin_cabsl (ldc) != 5.0L)
57 link_error ();
58 if (cabsl (3.0L + 4.0iL) != 5.0L)
59 link_error ();
60 if (__builtin_cabsl (3.0L + 4.0iL) != 5.0L)
61 link_error ();
62 #endif
64 return 0;