2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / gcc.dg / builtins-20.c
blob1bd95344ae9c0a4ec21a65cf01b8b7fb12218b24
1 /* Copyright (C) 2003 Free Software Foundation.
3 Verify that built-in math function constant folding doesn't break
4 anything and produces the expected results.
6 Written by Roger Sayle, 8th June 2003. */
8 /* { dg-do link } */
9 /* { dg-options "-O2 -ffast-math" } */
11 #include "builtins-config.h"
13 extern void link_error(void);
15 void test1(double x)
17 if (cos(x) != cos(-x))
18 link_error ();
20 if (sin(x)/cos(x) != tan(x))
21 link_error ();
23 if (cos(x)/sin(x) != 1.0/tan(x))
24 link_error ();
26 if (tan(x)*cos(x) != sin(x))
27 link_error ();
29 if (cos(x)*tan(x) != sin(x))
30 link_error ();
33 void test2(double x, double y)
35 if (-tan(x-y) != tan(y-x))
36 link_error ();
38 if (-sin(x-y) != sin(y-x))
39 link_error ();
42 void test1f(float x)
44 if (cosf(x) != cosf(-x))
45 link_error ();
47 #ifdef HAVE_C99_RUNTIME
48 if (sinf(x)/cosf(x) != tanf(x))
49 link_error ();
51 if (cosf(x)/sinf(x) != 1.0f/tanf(x))
52 link_error ();
54 if (tanf(x)*cosf(x) != sinf(x))
55 link_error ();
57 if (cosf(x)*tanf(x) != sinf(x))
58 link_error ();
59 #endif
62 void test2f(float x, float y)
64 if (-tanf(x-y) != tanf(y-x))
65 link_error ();
67 if (-sinf(x-y) != sinf(y-x))
68 link_error ();
72 void test1l(long double x)
74 if (cosl(x) != cosl(-x))
75 link_error ();
77 #ifdef HAVE_C99_RUNTIME
78 if (sinl(x)/cosl(x) != tanl(x))
79 link_error ();
81 if (cosl(x)/sinl(x) != 1.0l/tanl(x))
82 link_error ();
84 if (tanl(x)*cosl(x) != sinl(x))
85 link_error ();
87 if (cosl(x)*tanl(x) != sinl(x))
88 link_error ();
89 #endif
92 void test2l(long double x, long double y)
94 if (-tanl(x-y) != tanl(y-x))
95 link_error ();
97 if (-sinl(x-y) != sinl(y-x))
98 link_error ();
101 int main()
103 test1 (1.0);
104 test2 (1.0, 2.0);
106 test1f (1.0f);
107 test2f (1.0f, 2.0f);
109 test1l (1.0l);
110 test2l (1.0l, 2.0l);
112 return 0;